3. 在xscj数据库中查找xs表中男生和女生的人数。
select 性别, count(*)as '人数'
from xs
group by 性别;
4. 将xscj数据库中各专业名输出。
select 专业名
from xs
group by 专业名;
5. 求xscj数据库中各课程的学生数。
select 课程号,count(*)as '学生数'
from xs_kc
group by 课程号;
6. 求xscj数据库中各专业的平均总学分和各专业的人数。
select 课程号,avg(学分)as '平均总学分',count(*)as'各专业人数'
from xs_kc
group by 课程号;
7. 在xscj数据库上产生一个结果集,包括每个专业的男生人数、女生人数、总人数,以及学生总人数。
select 专业名,性别,count(*)as'人数'
from xs
group by 专业名,性别
with rollup;
8. 在xscj数据库上产生一个结果集,包括每门课程各专业的平均成绩、每门课程的总平均成绩和所有课程的总平均成绩。
select 课程名,专业名,avg(成绩)as '平均成绩'
from xs_kc,kc,xs
where xs_kc.课程号=kc.课程号 and xs_kc.学号=xs.学号
group by 课程名,专业名
with rollup;
**9. 查找xscj数据库中平均成绩在80分以上的学生的学号和平均成绩。 **
select 学号,avg(成绩)as '平均成绩'
from xs_kc
group by 学号
having avg(成绩)>=80;
10. 查找选修课程超过2门且成绩都在80分以上的学生的学号。
select 学号
from xs_kc
where 成绩>=80
group by 学号
having count(*)>2;
11. 查找计算机专业平均成绩在80分以上的学生的学号和平均成绩。
select 学号,avg(成绩)as '平均成绩'
from xs_kc
where 学号 in(select 学号 from xs where 专业名='计算机')
group by 学号
having avg(成绩)>80;
12. 求YGGL数据库中Employees表中的男性和女性的人数。
select sex, count(*)as '人数'
from employees
group by sex;
13. 在YGGL数据库中查找Employees表,按部门列出在各部门工作的员工的人数。
select departmentName,count(employeeID)
from departments,employees
where employees.departmentid=departments.departmentid
group by departmentName;
14. 查找Employees表,按员工的学历分组,列出本科、大专和硕士的人数。
select education,count(employeeid)
from employees
group by education;
15. 查找员工数超过3人的部门名称和员工数量。
select employees.departmentID,count(*) as 人数
from employees,departments
where employees.departmentid=departments.departmentID
group by employees.departmentID
having count(*) >3;
16. 按员工的工作年份分组,统计各个工作年份的人数,如工作1年的多少人,工作2年的多少人。
select workyear,count(*)as 人数
from employees
group by workyear;