软件测试常⽤SQL查询语句(⼀)⼀、简单查询
from > distinct > select > order by > limit
(1) 普通查询:select name,age from students;
(2) 起别名查询:select s.name,s.age from students as s;
(3) 分页查询:select name,age from students limit 0,10;
(4)排序查询:select name,age,id from students order by age desc,id asc;
(5)去重查询:select distinct age from students;
⼆、条件查询
from > where > distinct > select > distinct > order by > limit
eg: select name,age, from students where name=‘xiaoming’ and age=18;
三、⾼级查询(聚合函数)
sum求和 | avg平均数 | max最⼤数 | 最⼩数min
group by | 分组查询
(1) 求班级男⼥平均年龄分别为多少?
select sex avg(age) from students group by sex;
count(*)记录含空值记录数 | count(列名)不含空记录数
(2) 求班级男⼥分别为多少⼈?
select sex count(*) from students group by sex;
(3) 查询每个部门⾥,每种职位的平均底薪。
select deptno,job,count(*),avg(sal) from t_emp group by deptno,job order by deptno;
group_concat | 可以搭配group by使⽤,使某个字段连接成字符串
常用的sql查询语句有哪些
(4) 查询每个部门内底薪超过2000元的⼈数和员⼯姓名。
select deptno grouo_concat(ename) count(*) from t_emp where sal>=2000 group by deptno;
having | 跟在group by 后⾯的条件语句
eg: select sex avg(age) from students group by sex having age in(10,20);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。