2016/3/16 高级查询 ①连接查询 ②联合查询 ③子查询 无关 相关
高級查詢
1.連接查詢(對列的擴展)
第一種形式: 注意 , where 和后面 join on的比較 join換 ,號 on換where
select * from Info,Nation #會形成笛卡爾積
select * from Info,Nation where Info.Nation = Nation.Code #加上篩選條件
select Info.Code,Info.Name,Sex,Nation.Name,Birthday from Info,Nation where
Info.Nation = Nation.Code #查詢指定列
select Info.Code as '代號',Info.Name as '姓名',Sex as '性別',Nation.Name as '民
族',Birthday as '生日' from Info,Nation where Info.Nation = Nation.Code #換表頭
第二種形式: 注意 , where 和后面 join on的比較 join換 ,號 on換where
select * from Info join Nation #join連接
select * from Info join Nation on Info.Nation = Nation.Code #join on關鍵字
2.聯合查詢(對行的擴展) 關鍵詞 union
select * from Info where Nation = 'n002'
union
select * from Info where Code = 'p002'
3.子查詢(無關子查詢)
在一個SQL語句中,至少有兩個查詢,其中一個a查詢的結果作為另一個b的查詢條件,a成為里層
查詢或者子查詢,
b成為外層查詢或父查詢。
查詢民族為“漢族”的人員信息: 關鍵符號 =
select * from Info where Nation =(select Code from Nation where Name = '漢族')
查詢民族為“漢族”或者"回族"的人員信息 關鍵詞 in
select * from Info where Nation in (select Code from Nation where Name = '漢族' or
Name = '回族')
4.子查詢(相關子查詢)
查詢同一系列的 油耗要比平均油耗低的汽車信息
子查詢:select avg(Oil) from Car where Brand = ''
父查詢:select * from Car where Oil< 平均油耗
select * from Car a where a.Oil <(select avg(b.Oil) from Car b where b.Brand =
a.Brand)
轉載于:https://www.cnblogs.com/haodayikeshu/p/5285194.html
總結
以上是生活随笔為你收集整理的2016/3/16 高级查询 ①连接查询 ②联合查询 ③子查询 无关 相关的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】蓝牙物理链路类型:SCO和ACL链
- 下一篇: OC-NSArray