python基础下的mysql学习之操作命令(二)单表查询

一、完整的单表查询语句

select [distinct] *|字段1,字段2, ....

  from 表名

  [where 条件1]

  [group by 字段名 [having 条件2] ]

  [order by 字段名 [asc|desc] ]

  [limit [star],count ]

二、执行顺序(由上而下)

from 表名

where 条件

group by

select [distinct] *|字段

having 条件

order by

limit star,count

三、运算符

比较运算符:=   <>  !=  <   <=  >  >= 

逻辑运算符:and  or  not

优先级:

  1.小括号,not,比较运算符,逻辑运算符;

  2.and,or,如需先进行or,则使用();

四、带关键字的查询

where [not] in(元素1,元素2,....)  非连续的范围查询

where [not] between 值1 and 值2    连续的范围查询

where 字段名 is [not] null   空值查询

where 字段名 [not] like "匹配字符串"    模糊查询,其中可使用"%"进行0-多个匹配;使用"_"进行单个字符匹配

五、聚合函数

count()  计数

sum()  求和

avg()  求平均

max()  求最大

min()  求最小

使用: select 函数(字段) from 表名;

猜你喜欢

转载自www.cnblogs.com/wendaobiancheng/p/9075338.html