小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

單表查詢DQL

 Coder編程 2022-03-22

基本數(shù)據(jù)檢索:單表

復雜數(shù)據(jù)檢索:多表:連接查詢、子查詢(嵌套查詢)、集合運算

 

 

 

基本select語句:

  • select <檢索字段>
  • from <表>
  • where <檢索條件>
  • group by<分類>
  • having<檢索條件>
  • order by <排序字段>

操縱列:

  • 1.輸出所有列:select *
  • 2.輸出指定列:select <字段>[,...n]
  • 3.計算表達式:select <表達式>[,...n]
  • 4.設(shè)置列表標題名:<表達式> [AS] <別名>|<別名>=<表達式>
  • 5.消除重復記錄:distinct

 

 1 select * from <表名>     --查詢表中所有數(shù)據(jù)
 2 
 3 select <字段名>,<字段名>  form <表名>   --投影
 4 
 5 select <表達式> from <表名>  --查詢計算列
 6 --eg:表達式為:2020-sage    sage為字段名
 7 --:select 2020-sage from 表名
 8 
 9 --計算列沒有名稱,通常需要  命別名
10 --1.字段 as 別名 :           select 2020-sage as 別名 from 表名
11 --2.字段 別名,即as 可?。?/strong>     select 2020-sage  別名 from 表名
12 --3.別名=字段:               select 出身年=2020-sage  from 表名
13 
14 select [謂詞] 字段 from 表名
15 --1. distinct 去重 :        select distinct 2020-sage as 別名 from 表名

 

操作行

1.普通查詢:where <邏輯表達式>

2.模糊查詢:1. 運算符 like   2.通配符 :%任意個字符,_任意一個字符

select [謂詞] 字段 from 表名
--2.top  n:查詢記錄的前n行
select top 3 * from 表名     --選擇前 n 行
--3.top  n percent :查詢前n%行
select top 3 percent * from 表名     --選擇前 n% 行

select top n percent 字段 fromwhere 表達式 order by 排序字段名 [asc]/desc
--order 默認的排序方式是升序asc,可不寫

select top n percent with ties 字段 fromwhere 表達式 order by 排序字段名 [asc]/desc
--with ties 顯示排序字段的并列值
--eg: top 3 :但第三名與第四名排序字段相同,則with ties 使第三名和第四名都顯示出來

--in /not in (子查詢/表達式列表)  :過濾記錄
select  * from 表名 where grade in (88,99)

--between/not between  起始值 and 終止值 :過濾記錄
select  * from 表名 where grade between 80 and 90

--字段 like '正則表達式' :模糊匹配
select * from where 學號 like '%[1,4]'  --匹配以1,或4結(jié)尾的學號

 

 

 

分組查詢

group by 分組字段

 

聚合函數(shù)

 

 

select count(字段名)  fromgroup by 分組字段   --查找每個分組的記錄數(shù)量
--當使用 count(*)時,統(tǒng)計所有記錄
--當使用 count(字段名)是,統(tǒng)計記錄不包含null
--當使用 count(distinct 字段名)時,統(tǒng)計記錄不包含重復和null

 

若分組增加條件則使用 having,可在匯總后過濾

即,分組之前的條件使用where ,分組之后的條件使用having

 

 

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多