搜索所有
select * from user_form
查询多列
select id,name,age from user_form
查询结果去重
select distinct university from user_form
查询结果限制返回行数
select age from user_form limit 2
查询到结果重新命名
select name as user_name from user_form
查询有一个限制条件
select name from user_form where age=25
select name from user_form where age>20
select name from user_form where age!=25
查询区间限制的结果
select name from user_form where age>20 and age<25
select name from user_form where age between 21 and 24
where过滤空值
select name from user_form where university is not null
查询有多个限制条件
select name from user_form where age>20 and university='123'
select name from user_form where age>20 or university='123'
select name from user_form where age in(10,20,22)
select name from user_form where (age=20 and university='111')or(age>12 and university='222')
查询某一字段包含某字符串
select name from user_form where university like "%北京%"
select name from user_form where university regexp "北京"
查询最大值
select max(age) from user_form
查询数量
select count(age) from user_form where age=20
查询平均值-round(a,b)b为保留几位小数
select round(avg(age),2) from user_form where university='222'
分组按条件查询
select gender,age,count(gender) from user_form group by gender,age
分组过滤查询
select gender,avg(age) as avg_age from user_form group by gender having avg_age>20
分组排序查询
select gender,avg(age) as avg_age from user_form group by gender order by avg_age
查询两表关联信息
select a.name,age
from user_info as a,user_detail as b
where a.name=b.name and b.university='123'