命令综合
1、mysql> select * from t_worker ;
2、mysql> select distinct department_id from t_worker ;
3、mysql> select count(1) from t_worker ;
4、mysql> select max(wages) '最高工资',min(wages)"最低工资" from t_worker ;
5、mysql> select avg(wages) '平均工资',sum(wages)"总工资" from t_worker ;
6、create table work_date (id int, name varchar(20),work varchar(20) );
7、mysql> select name ,year(now())-year(borth_date) from t_worker where politics like '党员';
8、mysql> select name from t_worker where wages > 4000 and wages < 8000;
9、mysql> select name from t_worker where name like '孙%' or name like "李%";
10、
mysql> select department_id , worker_date ,name from t_worker where department_id != 101 and politics not like '党员'
-> group by department_id ,worker_date,name ;
11、mysql> select * from t_worker order by borth_date ;
12、mysql> select worker_id ,name from t_worker where wages = (select max(wages)from t_worker)
-> order by wages desc
-> limit 3 ;
13、mysql> select department_id ,count(1) from t_worker where politics like '党员'
-> group by department_id;
14、mysql> select department_id ,round(avg(wages),2),sum(wages) from t_worker
-> group by department_id;
15、mysql> select department_id ,count(1) from t_worker
-> group by department_id
-> having count(1) >= 3;
图表展示
总结:
多种不同的查询方法要想熟练使用关键是面对要求要有清晰的思路要搞清楚命令的运行机制,清楚明白先后顺序,一步一步筛选信息最终达到目标