生活随笔
收集整理的這篇文章主要介紹了
mysql 学习笔记13 查询语句强化
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用控制語(yǔ)句計(jì)算員工年工資
查詢?nèi)肼殨r(shí)間,晚于1982年1月1日的,(日期是可以進(jìn)行比較的)
where中l(wèi)ike的使用
select name, sal from users where like 'S%';
select name, sal from users where like '__O%';
order by,使用多個(gè)字段進(jìn)行排序
按照部門號(hào)升序而雇員工資降序排列
order by 使用別名進(jìn)行排序
5. 分頁(yè)查詢
查詢要求:
舉例:
limit 0,3
0表示其實(shí)位置,3表示需要多少條記錄
-------統(tǒng)計(jì)函數(shù)的相關(guān)使用-------
6. 顯示工資最高員工的名字,以及工作崗位:
7. 顯示工資高于平均工資的員工的信息:
8. 顯示平均公司低于2000的部門號(hào)和他的平均工資
9. 顯示各部門的平均工資和最高工資
10. 顯示每個(gè)部門的每種崗位的平均工資和最低工資
mysql> select avg(stsal), min(stsal), stjob, stdepno from staff group by stdepno, stjob;
+--------------+------------+-------+---------+
| avg(stsal) | min(stsal) | stjob | stdepno |
+--------------+------------+-------+---------+
| 10000.200000 | 10000.20 | 丞相 | 10 |
| 9000.200000 | 9000.20 | 軍師 | 10 |
| 2000.200000 | 2000.20 | 文員 | 10 |
| 5000.200000 | 5000.20 | 前鋒 | 20 |
| 2713.680000 | 2000.20 | 將軍 | 20 |
| 500.200000 | 500.20 | 太監(jiān) | 30 |
| 900.200000 | 900.20 | 皇妃 | 30 |
| 10000.200000 | 10000.20 | 皇帝 | 30 |
+--------------+------------+-------+---------+
統(tǒng)計(jì)所有雇員的平均工資,總計(jì)工資,最高工資和最低工資
mysql> select avg(stsal), sum(stsal), max(stsal), min(stsal) from staff;
+-------------+------------+------------+------------+
| avg(stsal) | sum(stsal) | max(stsal) | min(stsal) |
+-------------+------------+------------+------------+
| 4690.000000 | 60970.00 | 10000.20 | 500.20 |
+-------------+------------+------------+------------+
統(tǒng)計(jì)每種崗位的雇員總數(shù),平均工資
mysql> select avg(stsal), stjob, count(*) from staff group by stjob;
+--------------+-------+----------+
| avg(stsal) | stjob | count(*) |
+--------------+-------+----------+
| 10000.200000 | 丞相 | 1 |
| 9000.200000 | 軍師 | 1 |
| 5000.200000 | 前鋒 | 1 |
| 500.200000 | 太監(jiān) | 1 |
| 2713.680000 | 將軍 | 5 |
| 2000.200000 | 文員 | 1 |
| 900.200000 | 皇妃 | 1 |
| 10000.200000 | 皇帝 | 2 |
+--------------+-------+----------+
統(tǒng)計(jì)員工總數(shù),和 補(bǔ)助高于500的員工數(shù)
mysql> select count(stname), count( if(stcom>=500, stcom, null)) from staff;
+---------------+-------------------------------------+
| count(stname) | count( if(stcom>=500, stcom, null)) |
+---------------+-------------------------------------+
| 13 | 8 |
+---------------+-------------------------------------+
統(tǒng)計(jì)管理者的人數(shù)
mysql> select count(distinct(stmgr)) from staff;
+------------------------+
| count(distinct(stmgr)) |
+------------------------+
| 3 |
+------------------------+
總結(jié)
以上是生活随笔為你收集整理的mysql 学习笔记13 查询语句强化的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。