日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2016/3/16 高级查询 ①连接查询 ②联合查询 ③子查询 无关 相关

發布時間:2024/1/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 高级查询 ①连接查询 ②联合查询 ③子查询 无关 相关的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。