-
sql語句大全-Select查詢語句
- 2015-01-24 21:56 來源:未知
(1)Select 查詢語句
[,<目標列表達式> [AS 列名] ...] FROM <表名> [,<表名>…]
[WHERE <條件表達式> [AND|OR <條件表達式>...]
[GROUP BY 列名 [HAVING <條件表達式>>
[ORDER BY 列名 [ASC | DESC>
解釋:[ALL|DISTINCT] ALL:全部; DISTINCT:不包括重復行
<目標列表達式> 對字段可使用AVG、COUNT、SUM、MIN、MAX、運算符等
<條件表達式>
查詢條件 謂詞
比較 =、>,<,>=,<=,!=,<>,
確定范圍 BETWEEN AND、NOT BETWEEN AND
確定集合 IN、NOT IN
字符匹配 LIKE(“%”匹配任何長度,“_”匹配一個字符)、NOT LIKE
空值 IS NULL、IS NOT NULL
子查詢 ANY、ALL、EXISTS
集合查詢 UNION(并)、INTERSECT(交)、MINUS(差)
多重條件 AND、OR、NOT
<GROUP BY 列名> 對查詢結果分組
[HAVING <條件表達式>] 分組篩選條件
[ORDER BY 列名 [ASC | DESC> 對查詢結果排序;ASC:升序 DESC:降序
例1: select student.sno as 學號, student.name as 姓名, course as 課程名, score as 成績 from score,student where student.sid=score.sid and score.sid=:sid
例2:select student.sno as 學號, student.name as 姓名,AVG(score) as 平均分 from score,student where student.sid=score.sid and student.class=:class and (term=5 or term=6) group by student.sno, student.name having count(*)>0 order by 平均分 DESC
例3:select * from score where sid like '9634'
例4:select * from student where class in (select class from student where name='陳小小')
sql語句大全
語法:SELECT [ALL|DISTINCT] <目標列表達式> [AS 列名][,<目標列表達式> [AS 列名] ...] FROM <表名> [,<表名>…]
[WHERE <條件表達式> [AND|OR <條件表達式>...]
[GROUP BY 列名 [HAVING <條件表達式>>
[ORDER BY 列名 [ASC | DESC>
解釋:[ALL|DISTINCT] ALL:全部; DISTINCT:不包括重復行
<目標列表達式> 對字段可使用AVG、COUNT、SUM、MIN、MAX、運算符等
<條件表達式>
查詢條件 謂詞
比較 =、>,<,>=,<=,!=,<>,
確定范圍 BETWEEN AND、NOT BETWEEN AND
確定集合 IN、NOT IN
字符匹配 LIKE(“%”匹配任何長度,“_”匹配一個字符)、NOT LIKE
空值 IS NULL、IS NOT NULL
子查詢 ANY、ALL、EXISTS
集合查詢 UNION(并)、INTERSECT(交)、MINUS(差)
多重條件 AND、OR、NOT
<GROUP BY 列名> 對查詢結果分組
[HAVING <條件表達式>] 分組篩選條件
[ORDER BY 列名 [ASC | DESC> 對查詢結果排序;ASC:升序 DESC:降序
例1: select student.sno as 學號, student.name as 姓名, course as 課程名, score as 成績 from score,student where student.sid=score.sid and score.sid=:sid
例2:select student.sno as 學號, student.name as 姓名,AVG(score) as 平均分 from score,student where student.sid=score.sid and student.class=:class and (term=5 or term=6) group by student.sno, student.name having count(*)>0 order by 平均分 DESC
例3:select * from score where sid like '9634'
例4:select * from student where class in (select class from student where name='陳小小')
最新更新
C#教程之C#8.0——異步流(AsyncStream)
C#教程之C#從零單排上王者系列---數據類型
C#教程之簡潔實用Socket框架DotNettySocket
C#教程之阿拉伯數字轉換為中文數字/中文
C#教程之C#簡單工廠案例
C#教程之C# 修飾符
C#教程之C# virtual 和 abstract 區別
C#教程之從圖片中把人物摳出來
C#教程之.net平臺下對C#代碼的編譯
C#教程之如何判斷當前修改過的datatable的
JavaScript教程之Mac安裝vue
JavaScript教程之nodejs + webpack4 + babel6 結合寫
JavaScript教程之Clean Code之JavaScript代碼示例
JavaScript教程之AJAX調用數據,滾動到底部
JavaScript教程之聊聊 Vue 中 title 的動態修改
JavaScript教程之使用JavaScript獲取url中的參
JavaScript教程之前端之json,ajax和jsonp
JavaScript教程之electron——ipcMain模塊、ip
JavaScript教程之前端之移動端庫和框架bo
JavaScript教程之大項目之網上書城(三)—
access數據庫之隨說秋色園從Access升遷到
access數據庫之微信公眾平臺開發(26) ACCE
access數據庫之ACCESS TOKEN
access數據庫之當爬蟲被拒絕時(Access Deni
access數據庫之當爬蟲被拒絕時(Access Deni
access數據庫之使用PowerDesigner生成Access數據
access數據庫之讓ADO.NET Entity Framework 支持
access數據庫之Web API與OAuth:既生access to
access數據庫之[認證 & 授權] 6. Permissi
access數據庫之[認證 & 授權] 6. Permissi