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

  1. 對數據分組的總結

在這里插入圖片描述
舉例:統計各個部門的平均工資,并且是大于1000的,并且按照平均工資從高到底排序

mysql> select avg(stsal) as myavgsal, stdepno from staff group by stdepno having myavgsal > 1000 order by myavgsal desc;
+-------------+---------+
| myavgsal    | stdepno |
+-------------+---------+
| 7000.200000 |      10 |
| 5350.200000 |      30 |
| 3094.766667 |      20 |
+-------------+---------+
  1. 笛卡爾積的原理
    在這里插入圖片描述
    多表查詢練習:
  2. 顯示員工名,工資,及所在部門的名字
select staff.stname , staff.stsal, department.dname from staff, department where department.deptno = staff.stdepno;
  1. 顯示部門號為10的部門名,員工名,工資,
select staff.stname , staff.stsal, department.dname from staff, department where department.deptno = staff.stdepno and department.deptno = 10;
  1. 顯示每個員工的姓名,工資, 及其工資的級別
select staff.stname, staff.stsal, salalevel.slevel from staff, salalevel where staff.stsal >= slower and staff.stsal <= shig;
  1. 顯示每個員工姓名,工資,以及部門名,以及工資級別
    這樣就設計到三張表的關聯查詢,三張表為了避免笛卡爾積, 就需要至少兩個查詢條件
select staff.stname, staff.stsal , department.dname, salalevel.slevel from staff,department,salalevel where staff.stdepno = department.deptno and staff.stsal >= salalevel.slower and staff.stsal <= salalevel.shig;

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

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

相關文章

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

轉 wiki https://zh.wikipedia.org/zh-cn/公開密鑰加密 公開密鑰密碼學 &#xff08;英語&#xff1a;Public-key cryptography&#xff09;&#xff0c;也稱為非對稱式密碼學&#xff08;英語&#xff1a;asymmetric cryptography&#xff09;&#xff0c;是密碼學的一種算…

mysql 學習筆記 多表查詢02

把一張表 想象成兩張表&#xff0c;進行多表查詢 舉例&#xff1a; 查詢 所有員工的 姓名 以及 其 上級姓名 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安裝&#xff08;mac&#xff09; brew install redis 如果需要后臺運行 redis 服務&#xff0c;使用命令 brew services start redis 如果不需要后臺服務&#xff0c;則使用命令 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

centos 無法連接網絡

最小化安裝&#xff0c;沒有ifconfig默認沒法聯網 cd /etc/sysconfig/network-scripts/ sudo vi ifcfg-en33 也有可能是其他后綴 找到ONBOOTno service network restart 然后yum install net-tools