MySQL基礎三

來源:互聯網
上載者:User

標籤:外串連   class   1.2   inner   類型   篩選   sql基礎   like   select   

1 SQL991.1 SQL99文法
select 查詢列表from 表1 [連線類型] join 表2 on 串連條件where 篩選條件;

 

  • 連線類型:
  • 內串連  :inner
  • 外串連:
    • 左外串連: left outer
    • 右外串連:right outer
  • 交叉串連:cross  
1.2 SQL99文法的內串連1.2.1 內串連的文法
select 查詢列表from 表1 inner join 表2 on 串連條件[where 篩選條件];
1.2.2 應用
  • 樣本:查詢員工名和部門名
SELECT    e.last_name,    d.department_nameFROM    employees eINNER JOIN departments d ON e.department_id = d.department_id;

 

  • 樣本:查詢名字中包含e的員工名和工種名
SELECT    e.last_name,    j.job_titleFROM    employees eINNER JOIN jobs j ON e.job_id = j.job_idWHERE    e.last_name LIKE ‘%e%‘;

 

  • 樣本:查詢部門個數>3的城市名和部門個數
SELECT    l.city,    count(*) `count`FROM    departments dINNER JOIN locations l ON d.location_id = l.location_idGROUP BY    l.cityHAVING    `count` > 3;

 

  • 樣本:查詢那個部門的員工個數>3的部門名和員工個數,並按照個數降序
SELECT    d.department_name,    count(*) 員工個數FROM    employees eINNER JOIN departments d ON e.department_id = d.department_idGROUP BY    d.department_nameHAVING    員工個數 > 3;

 

  • 樣本:查詢員工名、部門名、工種名,並按照部門名降序
SELECT    e.last_name 員工名,    d.department_name 部門名,    j.job_title 工種名FROM    employees eINNER JOIN departments dINNER JOIN jobs j ON e.department_id = d.department_idAND e.job_id = j.job_idORDER BY    部門名;

 

  • 樣本:

 

MySQL基礎三

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.