1.普通查询

select * from info; #查询所有内容

select Code,Name from Info #查询某几列

2.条件查询

select * from Info where Code='p001' #条件查询

select * from Info where Nation ='n001' and Sex= true #条件之间并的关系
select * from Info where Nation = 'n001' and sex = '1'

select * from Info where Sex = false or Nation = 'n002'#条件之间或者的关系

3.模糊查询(搜索关键字)

select * from Chinastates where areaname like '中%' #查询以中开头的

select * from Chinastates where Areaname like '%城%' #查询包含 城的信息

select * from Chinastates where Areaname like '_城%' #查询城 在第二个位置出现的数据

4.排序

select * from Car order by Code desc #desc降序 asc升序

select * from Car order by Brand

select * from Car order by Brand,Powers #按照两个列排序

5.统计查询(聚合函数)

select count(*) from Car #查询总条数 * 代表所有列

select count(Code) from Car #查询某一列

select max(Price) from Car #查询 price列里的最大值

select min(price) from Car #查询最小值

select avg(price) from Car #查询平均值

select sum(price) from Car #查询总和

6.分组查询
select Brand,count(*) from Car group by Brand #根据系列(Brand)分组(group)查看每组的数据条数

select Code,Brand,count(*) from Car group by Brand #根据Brand分组查看Code,Brand的数据条

select * from Car group by Brand having count(*) >2 #查询分组之后数据条数大于2的,group后面不能加 where

7.分页查询
select * from Car limit 0,5 #查询跳过0条 取5条

select * from Car limit 5,5 #跳过几条取几条数据

MySQL简单查询的更多相关文章

  1. MySQL简单查询详解-单表查询

    MySQL简单查询详解-单表查询 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查询的执行路径 一条SQL查询语句的执行过程大致如下图所示: 1>.客户端和服务端通过my ...

  2. MySQL简单查询和单表查询

    MySQL记录操作 概览 MySQL数据操作: DML 在MySQL管理软件中,可以通过SQL语句中的DML语言来实现数据的操作,包括 使用INSERT实现数据的插入 UPDATE实现数据的更新 使用 ...

  3. MySQL简单查询语句练习

    数据查询语法(DQL) DQL就是数据查询语言,数据库执行DQL语句不会对数据进行改变,而是让数据库发送结果集给客户端. 语法: SELECT selection_list /*要查询的列名称*/ F ...

  4. mysql基础查询语法

    一.mysql查询的五种子句 where子句(条件查询):按照“条件表达式”指定的条件进行查询. group by子句(分组):按照“属性名”指定的字段进行分组.group by子句通常和count( ...

  5. MySQL —— 基本查询方法

    MySQL —— 简单查询与按条件查询 在MySQL中从数据表中查询数据的基本语句时select语句.  select语句基本语法格式:      select 查询内容       from 表名  ...

  6. 简单的php Mysql类(查询 删除 更新)

    php Mysql类一般都包括了几乎我们常用的数据库操作方法,这里只提供了查询 删除 更新三种操作,算不是很全只是一个简单的数据库查询类了.      代码如下 复制代码 class mysql { ...

  7. MySQL之单表查询 一 单表查询的语法 二 关键字的执行优先级(重点) 三 简单查询 四 WHERE约束 五 分组查询:GROUP BY 六 HAVING过滤 七 查询排序:ORDER BY 八 限制查询的记录数:LIMIT 九 使用正则表达式查询

    MySQL之单表查询 阅读目录 一 单表查询的语法 二 关键字的执行优先级(重点) 三 简单查询 四 WHERE约束 五 分组查询:GROUP BY 六 HAVING过滤 七 查询排序:ORDER B ...

  8. MySql 简单统计查询消耗时间脚本

    MySql 简单统计查询消耗时间脚本 by:授客 QQ:1033553122 drop procedure if exists selectTime; delimiter; create proced ...

  9. mysql 数据操作 单表查询 简单查询 避免重复DISTINCT

    创建数据库company create database company charset=utf8; use company; company.employee 员工id id int 姓名 emp_ ...

随机推荐

  1. Autofact 的使用

    资料: http://www.cnblogs.com/linhan/p/4298971.html --其他博友 http://autofac.org/# --官网 http://efmvc.codep ...

  2. swift和 oc 混编2-备

    在Swift语言出现之前,开发iOS或OS X应用主要使用Objective-C语言,此外还可以使用C和C++语言,但是UI部分只能使用Objective-C语言. 选择语言 Swift语言出现后,苹 ...

  3. 不要if else的编程

    http://news.cnblogs.com/n/194216/ 英文原文:Unconditional Programming ] 本文作者介绍 Michael Feathers Michael F ...

  4. LeetCode _ Gas Station

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  5. HDOJ 1076 An Easy Task(闰年计算)

    Problem Description Ignatius was born in a leap year, so he want to know when he could hold his birt ...

  6. HDOJ 1197 Specialized Four-Digit Numbers

    Problem Description Find and list all four-digit numbers in decimal notation that have the property ...

  7. matrix矩阵求逆 与解方程模板 留做备用 (有bug,待补充)

    // // main.cpp // 矩阵求逆 // // Created by 唐 锐 on 13-6-20. // Copyright (c) 2013年 唐 锐. All rights reser ...

  8. vi查找

    /pattern<Enter> :向下查找pattern匹配字符串 ?pattern<Enter>:向上查找pattern匹配字符串 使用了查找命令之后,使用如下两个键快速查找 ...

  9. java笔记4之比较运算符

    /*    比较运算符:        ==,!=,>,>=,<,<=            特点:        无论你的操作是简单还是复杂,结果是boolean类型.   ...

  10. phpstorm xdebug调试设置样式

    由于本人比较喜欢白底的phpstorm开发环境,所以XDEBUG断点调试,F8时默认是没有背景色的,phpstorm中的设置方式如下 files -> settings -> Editor ...