select
查询项
select*from 表名 查询全部列
select distinct 列名 from 表名 查询指定列,重复项不显示,经常用于获取列表,不显示重复项,一般不适用与两个列,因为很少有两个列一样的,特殊统计
select id,name from 表名 查询指定列名
select name myname from 表名 指定结果列别名
select 表名.列名 ,。。from 表名 指定列所属表,多表查询时使用
select sum(id),count(amount)from 表名 使用聚合函数用于统计
select sum(case name when ‘assss’ then 1 else 0 end)from class
判断name列是否为 ’asss‘ 值,是=1,否=0,通过sum()获取统计结果
获取单列不同状态的统计
查询条件
条件
true
select*from 表名 where id=100 基本条件查询
select*from 表名 别名 where name=‘aa’ and sex=1 复合查询,表别名
运算符