查询语句格式
select 必选
from 必选
where
group by
having
order by
limit
count()
count(*) 返回NULL和非NULL的行数,即所有行。
count(exp) 返回exp为非NULL的行数。
count(distinct exp) 返回exp无重复且非NULL的行数。
count()在group by 中在having可能有用
exists
exists(后面加select语句)
exists关心后面括号里的集合是不是空集
空集是NULL,返回FALSE
不是空集,返回TRUE
简单理解是筛选出符合后面括号里条件的值
limit
limit +n 只输出前n行信息
limit n,m 从n条记录开始,返回m条记录
group_concat()
group_concat(distinct exp order by separator '')
distinct 可选,去重
exp 行名
order by 列表内容排序规则
separator 以什么东西分隔开
返回一个列表,即字符串列表
like
字符串模糊匹配
like '%数据%'
%任意数量字符
_单个字符
NULL
查询条件where中用
is NULL 是NULL
is not NULL 不是NULL
AS
设置别名
在select中也能添加不存在的列
如 select ‘学生’ as type 在type这一列,值都是学生
也可以直接添加 select 学生
order by
asc 升序
desc 降序
in ()
存在于括内列表内
not in ()表示不存在
一般在in 前还要加一个变量如 sno in()
round()
round(grade) 取整数
round(grade , 2) 取两位小数
union
可以将两个查询结果合并到一个表
select a
union
select b
未完待续---------