1、mysql> select * from grade;
2、mysql> select id,firstname,lastname from grade;
3、mysql> select firstname,lastname from grade
-> where id<4;
4、mysql> select * from grade
-> where sex='f';
5、mysql> select * from grade
-> where id in(2,4,6);
6、mysql> select * from grade
-> where math between 85 and 94;
7、mysql> select * from grade
-> where firstname like 'A%';
8、mysql> select * from grade
-> where firstname like 'A%' and firstname like '%e';
9、mysql> select * from grade
-> where firstname like '%I%';
10、mysql> select * from grade
-> where firstname like 'A____';
11、mysql> select * from grade
-> where english between 80 and 90;
12、mysql> select * from grade
-> where math>90 or chinese>90;
13、mysql> select * from grade
-> where id not in(1,3,5,7);
14、mysql> select distinct sex from grade;
15、mysql> select distinct lastname from grade;
16、mysql> select count(*) from grade;
17、mysql> select count(*) from grade
-> where english=80;
18、mysql> select sum(math) from grade;
19、mysql> select sum(math) from grade
-> where sex='f';
20、mysql> select avg(english) from grade;
21、mysql> select avg(english) from grade
-> where sex='m';
22、mysql> select max(math) from grade;
23、mysql> select max(math) from grade
-> where sex='m';
24、mysql> select * from grade
-> order by math asc;
25、mysql> select * from grade
-> order by sex asc, chinese desc;
26、mysql> select count(*) from grade
-> group by sex;
27、mysql> select lastname,count(*) from grade
-> group by lastname
-> ;
28、mysql> select lastname,sum(math) from grade
-> group by lastname
-> having sum(math)<100;
29、mysql> select * from grade limit 2,4;
30、mysql> select * from grade
-> where sex='m' and (math+chinese+english)/3>85;
1、mysql> select name from emp,dept
-> where emp.dept2=dept.dept1
-> and age>all(select age from emp where emp.dept2=102);
2、mysql> select name from emp,dept
-> where emp.dept2=dept.dept1
-> and incoming in (select min(incoming) from emp
-> group by dept.dept_name
-> having dept_name='财务');
3、mysql> select dept_name from emp left join dept
-> on emp.dept2=dept.dept1
-> group by dept_name
-> having sum(incoming)>9000;
4、mysql> select name,dept_name from emp,dept
-> where emp.dept2=dept.dept1
-> and age=(select max(age) from emp where incoming between 7500 and 8500);
5、mysql> select worktime_start from emp,dept
-> where emp.dept2=dept.dept1
-> and incoming =(select min(incoming) from emp left join dept on emp.dept2=dept.dept1
-> where dept_name='销售');
6、mysql> select name from emp left join dept
-> on emp.dept2=dept.dept1
-> where incoming>2000 and dept_name='财务';
7、mysql> select avg(incoming),dept_name from emp left join dept
-> on emp.dept2=dept.dept1
-> group by dept_name;
8、mysql> select sid from emp left join dept
-> on emp.dept2=dept.dept1
-> where dept_name='IT技术';
9、mysql> select sum(incoming) from emp left join dept
-> on emp.dept2=dept.dept1
-> where dept_name='财务';
10、mysql> select distinct dept_name from emp,dept
-> where dept.dept1 not in(select dept2 from emp);
11、mysql> select dept1,dept_name from emp,dept
-> where dept.dept1=emp.dept2
-> and incoming>7000;
12、mysql> select sum,dept_name from dept left join
-> (select sum(incoming) sum,dept2 from emp group by dept2) e
-> on dept.dept1=e.dept2;
13、mysql> select name,dept_name from dept left join emp
-> on dept.dept1=emp.dept2
-> where age in(select max(age) from emp group by dept2);
14、mysql> select incoming,dept_name from emp,dept
-> where dept.dept1=emp.dept2
-> and name='李四';
15、mysql> select name,dept_name,incoming from emp join dept
-> on dept.dept1=emp.dept2
-> where(dept2,incoming)
-> in (select max(incoming),dept2 from emp group by dept2,dept.dept_name)
-> order by incoming desc;