MYSSQL基本语句

 emploee_info的内容如下:+------+---------------+--------+---------+------------+--------+-------------+----------------+-----------------------+

| id   | name          | genter | dept_id | join_time  | salary | phone       | address        | description           |

+------+---------------+--------+---------+------------+--------+-------------+----------------+-----------------------+

|    1 | liuyongcun    | F      | 1       | 2012-11-22 |   4000 | 18298494343 | beijingjinsong | NULL                  | 

|    2 | lilei         | M      | 2       | 2012-11-22 |   5000 | 18298494443 | tiantang1hao   | zhejiahuohenlan       | 

|    3 | chunge        | F      | 2       | 2012-11-22 |   4500 | 18238494443 | tiantang2hao   | xinchunge,deyongsheng | 

|    4 | ziteng        | M      | 3       | 2012-11-25 |   5500 | 18238494453 | tiantang1hao   | duzihenteng           | 

|    5 | zouying       | M      | 4       | 2012-11-25 |   5000 | 18238494454 | tiantang2hao   | xiaoyingying          | 

|    6 | zhangmingyang | M      | 2       | 2012-11-27 |   4500 | 18238494457 | tiantang1hao   | NULL                  | 

|    7 | liyanen       | M      | 1       | 2012-11-22 |   5500 | 18238494459 | tiantang2hao   | henshenqi             | 

|    8 | dachun        | F      | 2       | 2012-12-12 |   5000 | 34355454112 | tiantang1hao   | chungeshengjiban      | 

+------+---------------+--------+---------+------------+--------+-------------+----------------+-----------------------+

 

 

1.按名字查找

select  * from emploee_info where name='lilei';

2.按薪水查找>=5000的员工。

select * from emploee_info where salary>=5000;

3.每个部门多少人。

select dept_id,count(*) from emploee_info group by dept_id;

4.每个部门的平均薪水。

select dept_id,avg(*) from emploee_info group by dept_id;

5.description为空的人。

select * from emploee_info where description is null;

6.每个部门女员工薪水最多的。

select dept_id,max(salary) from emploee_info where genter='F' and group by dept_id;

7.名字是以l开头的人。

select * from emploee_info where name like 'l%';

你可能感兴趣的:(sql语句)