素材: 表名:worker-- 表中字段均为中文,比如 部门号 工资 职工号 参加工作 等
mysql8.0 [chap03]>select * from worker;
mysql8.0 [chap03]>select distinct(部门号) from worker;
mysql8.0 [chap03]>select count(*) from worker;
mysql8.0 [chap03]>select max(工资),min(工资) from worker;
mysql8.0 [chap03]>select avg(工资),sum(工资) from worker;
mysql8.0 [chap03]>create table 工作日期表 select 职工号,姓名,工作时间 from worker;
mysql8.0 [chap03]>show tables;
mysql8.0 [chap03]>select * from 工作日期表;
mysql8.0 [chap03]>select 职工号,姓名,2023-year(出生日期) from worker;
mysql8.0 [chap03]>select 职工号,姓名,出生日期 from worker where 姓名 like '张%';
mysql8.0 [chap03]>select 姓名,工作时间 from worker where year(出生日期)<1996;
mysql8.0 [chap03]>select 姓名 from worker where 工资 between 1000 and 5000;
mysql8.0 [chap03]>select 姓名 from worker where 姓名 regexp '(^张|^李)';
mysql8.0 [chap03]>select 部门号, 职工号,姓名,政治面貌 from worker where 部门号 in (102,103);
mysql8.0 [chap03]>select * from worker order by 出生日期;
mysql8.0 [chap03]>select 职工号,姓名,工资 from worker order by 工资 desc limit 3;
mysql8.0 [chap03]>select 部门号,count(政治面貌) from worker where 政治面貌='党员' group by 部门号;
mysql8.0 [chap03]>select 部门号,sum(工资),avg(工资) from worker group by 部门号;
mysql8.0 [chap03]>select 部门号,count(*) from worker group by 部门号 having count(*)>=2;
mysql8.0 [chap03]>select * from student;
mysql8.0 [chap03]>select * from student limit 1,3;
mysql8.0 [chap03]>select id,name,department from student;
mysql8.0 [chap03]>select * from student where department regexp '(计算机系|英语系)';
mysql8.0 [chap03]>select * from student where 2023-birth between 18 and 22;
mysql8.0 [chap03]>select department,count(*) from student group by department;
mysql8.0 [chap03]>select c_name,max(grade) from score group by c_name;
mysql8.0 [chap03]>select st.name,sc.c_name,sc.grade from student st join score sc on st.id=sc.stu_id where st.name='李四';
mysql8.0 [chap03]>select st.id,st.name,sc.c_name,sc.grade from student st left outer join score sc on st.id=sc.stu_id;
mysql8.0 [chap03]>select st.name,sum(sc.grade) from student st left outer join score sc on st.id=sc.stu_id group by st.name;
mysql8.0 [chap03]>select c_name,avg(grade) from score group by c_name;
mysql8.0 [chap03]>select sc.stu_id,st.name,sc.grade from score sc join student st on st.id=sc.stu_id where c_name='计算机' and grade<95;
mysql8.0 [chap03]>select sc.stu_id,group_concat(sc.c_name),st.name,st.sex from score sc,student st where st.id=sc.stu_id group by sc.stu_id having group_concat(sc.c_name)='计算机,英语';
mysql8.0 [chap03]>select * from score where c_name='计算机' order by grade desc;
mysql8.0 [chap03]>select * from student st,score sc where st.id=sc.stu_id;
mysql8.0 [chap03]>select * from student st,score sc where st.id=sc.stu_id and st.name regexp'(^张|^王)';
mysql8.0 [chap03]>select * from student st,score sc where st.id=sc.stu_id and address like '湖南%';