mysql 學習筆記13 查詢語句強化

  1. 使用控制語句計算員工年工資
    在這里插入圖片描述
  2. 查詢入職時間,晚于1982年1月1日的,(日期是可以進行比較的)
    在這里插入圖片描述
  3. where中like的使用
    在這里插入圖片描述
select name, sal from users where like 'S%';
select name, sal from users where like '__O%';
  1. order by,使用多個字段進行排序
    按照部門號升序而雇員工資降序排列
    在這里插入圖片描述

order by 使用別名進行排序
在這里插入圖片描述
5. 分頁查詢
查詢要求:
在這里插入圖片描述
舉例:
limit 0,3
0表示其實位置,3表示需要多少條記錄
在這里插入圖片描述
-------統計函數的相關使用-------
6. 顯示工資最高員工的名字,以及工作崗位:
在這里插入圖片描述
7. 顯示工資高于平均工資的員工的信息:
在這里插入圖片描述
8. 顯示平均公司低于2000的部門號和他的平均工資在這里插入圖片描述
9. 顯示各部門的平均工資和最高工資
在這里插入圖片描述
10. 顯示每個部門的每種崗位的平均工資和最低工資

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 | 太監     |      30 |
|   900.200000 |     900.20 | 皇妃      |      30 |
| 10000.200000 |   10000.20 | 皇帝     |      30 |
+--------------+------------+-------+---------+
  1. 統計所有雇員的平均工資,總計工資,最高工資和最低工資
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 |
+-------------+------------+------------+------------+
  1. 統計每種崗位的雇員總數,平均工資
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 | 太監     |        1 |
|  2713.680000 | 將軍      |        5 |
|  2000.200000 | 文員     |        1 |
|   900.200000 | 皇妃      |        1 |
| 10000.200000 | 皇帝     |        2 |
+--------------+-------+----------+
  1. 統計員工總數,和 補助高于500的員工數
mysql> select count(stname), count( if(stcom>=500, stcom, null)) from staff;
+---------------+-------------------------------------+
| count(stname) | count( if(stcom>=500, stcom, null)) |
+---------------+-------------------------------------+
|            13 |                                   8 |
+---------------+-------------------------------------+
  1. 統計管理者的人數
mysql> select count(distinct(stmgr)) from staff;
+------------------------+
| count(distinct(stmgr)) |
+------------------------+
|                      3 |
+------------------------+

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/382465.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/382465.shtml
英文地址,請注明出處:http://en.pswp.cn/news/382465.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mysql學習筆記14 多表查詢初步

對數據分組的總結 舉例:統計各個部門的平均工資,并且是大于1000的,并且按照平均工資從高到底排序 mysql> select avg(stsal) as myavgsal, stdepno from staff group by stdepno having myavgsal > 1000 order by myavgsal desc; ----…

SSH加密密碼中的非對稱式密碼學

轉 wiki https://zh.wikipedia.org/zh-cn/公開密鑰加密 公開密鑰密碼學 (英語:Public-key cryptography),也稱為非對稱式密碼學(英語:asymmetric cryptography),是密碼學的一種算…

mysql 學習筆記 多表查詢02

把一張表 想象成兩張表,進行多表查詢 舉例: 查詢 所有員工的 姓名 以及 其 上級姓名 select s1.stname, s2.stname from staff as s1, staff as s2 where s1.stmgr s2.stid;查詢 員工李巖的 上級姓名 select s1.stname, s2.stname from staff as s1…

Mac Redis安裝入門教程

redis安裝(mac) brew install redis 如果需要后臺運行 redis 服務,使用命令 brew services start redis 如果不需要后臺服務,則使用命令 redis-server /usr/local/etc/redis.conf 啟動redis服務 執行以下命令 /usr/local/bin…

Shell 腳本基礎學習

查詢手冊 菜鳥教程 for循環和seq的使用 echo "method 1" for i in seq 1 10; doecho $i; doneecho "method 2" for i in {1..10} doecho $i; doneecho "method 3" for i in seq 1 2 10; doecho $i; done進入目錄創建文件重定向內容 cd Test …

mysql 學習筆記15 子查詢

子查詢定義&#xff1a; 單上子查詢舉例&#xff1a; 顯示與 員工 關平 同一部門的員工&#xff0c; 但不包括關平 select * from staff where staff.stdepno (select staff.stdepno from staff where stname關平) and staff.stname<> 關平 ;多行子查詢舉例&#xff…

shell自學筆記

文章目錄重定向數值比較邏輯操作符使用范圍關于文件判斷測試表達式test [] [[]] (())的區別sed教程AWK教程重定向 0表示標準輸入 1表示標準輸出 2表示標準錯誤輸出 默認為標準輸出重定向&#xff0c;與 1> 相同 2>&1 意思是把 標準錯誤輸出 重定向到 標準輸出. &…

ffmpeg簡單使用小記

1. 使用ffmpeg 進行普通切片&#xff08;ts&#xff09;操作 .\ffmpeg.exe -i a.mp4 -y -f hls -c copy -hls_time 10 .\s.m3u82. 使用ffmpeg 對視頻進行設置旋轉參數為0 .\ffmpeg.exe -i a.mp4 -metadata:s:v:0 rotate0 -c copy outputfile.mp43. 使用文件對視頻進行加密 .\…

python3安裝教程配置配置阿里云

配置全新阿里云 Linux iz2ze0ajic0vbvwnjhw2bwz 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux 安裝依賴包 wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1rc1.tar.xz 新建一個文件夾存放python3 mkdir /u…

python 使用requests模塊進行 視頻文件的下載

公司項目需要下載一批視頻文件&#xff0c; 格式是mp4和mkv的&#xff0c;就借助request模塊進行了下載&#xff0c;前提是源服務器返回文件的大小&#xff0c;以及可以接受 請求頭headers中帶有Range參數 以下是下載邏輯&#xff1a; resp requests.head(urlreal_video_url)…

Git的多人協作和分支處理測試

首先配置ssh密鑰 克隆項目 配置兩臺主機&#xff08;一臺本地mac&#xff0c;一臺云服務器&#xff09;通過這樣的方式模擬多人開發。 創建分支 [root ~/Git_test_多人協作和沖突合并/branch_test]$ ls README.md [root ~/Git_test_多人協作和沖突合并/branch_test]$ git b…

python 碎片整理 threading模塊小計

threading模塊中&#xff0c; start()與run()方法的區別 threading.start() 方法是開啟一個線程 threading.run() 方法則是普通的函數調用

git教程目錄

git入門教程 PyCharm和git安裝教程 Git的多人協作和分支處理測試

msyql 禁止遠程訪問

1. use mysql 2. select host , user from user; 查看用戶 與 對應的host 3. 將 host 中是 %的改為 localhost&#xff0c; 酌情也可以其他用戶 的host限制為localhost update user set host "localhost" where user "root" and host "%" 4. …

mysql索引回表

先索引掃描&#xff0c;再通過ID去取索引中未能提供的數據&#xff0c;即為回表。 建表 mysql> create table T( id int primary key, k int not null, name varchar(16), index (k))engineInnoDB;如果語句是 select * from T where ID500&#xff0c;即主鍵查詢方式&am…

C++ 執行cmd命令 并獲取輸出

這是參考別人的 &#xff0c;具體來源忘了&#xff0c;唉&#xff0c;等想起來一定補上出處 頭文件 PipeCmd.h #ifndef _PIPE_CMD_H_ #define _PIPE_CMD_H_#include <Windows.h>// 執行 cmd 命令, 并獲取執行結果數據 BOOL PipeCmd(char *pszCmd, char *pszResultBuffe…

iterm2 保存阿里云登陸并防止斷開連接

commando edit profiles新增一個頁面 添加命令 ssh -A -p 22 -o ServerAliveInterval60 rootIP

QString中包含中文的時候, 轉為char *

轉載自 https://blog.csdn.net/mihang2/article/details/39026865 QString中包含中文的時候&#xff0c; 轉為char * void FileEncWidget::QString2ANSI(QString text, char **pOut) {std::wstring wIn text.toStdWString();char *pcstr (char *)malloc(sizeof(char)*(2 * w…

brew安裝

官網&#xff1a;http://brew.sh/ 安裝軟件&#xff1a;brew install 軟件名&#xff0c;例&#xff1a;brew install wget搜索軟件&#xff1a;brew search 軟件名&#xff0c;例&#xff1a;brew search wget卸載軟件&#xff1a;brew uninstall 軟件名&#xff0c;例&#…

關于異步IO模型的學習

看到兩篇不錯的文章&#xff0c;轉載了&#xff1a; https://www.cnblogs.com/fanzhidongyzby/p/4098546.html https://www.cnblogs.com/aspirant/p/9166944.html