DQL查询语句内容整理
生活随笔
收集整理的這篇文章主要介紹了
DQL查询语句内容整理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
select * from t_hq_ryxx;select bianh,xingm from t_hq_ryxx;--為字段名定義別名
select bianh as 編號,xingm as 姓名 from t_hq_ryxx;select bianh 編號 from t_hq_ryxx;select bianh || xingm as 編號和姓名 from t_hq_ryxx;select bianh as bh, t.* from t_hq_ryxx t order by bianh desc;--order by 排序,desc降序排序
select bianh as bh, t.* from t_hq_ryxx t order by xingb desc,bum desc;--nulls last/first的用法,desc或者asc要放在nulls前面
select bianh ,xingm ,bum,xingb from t_hq_ryxx t order by bum desc nulls last,xingb;--選擇排序為8的字段
select * from t_hq_ryxx order by 8;--由bum和bianh列來定義排序方式
select * from t_hq_ryxx order by bum || bianh;
--相加的字段若有空則結果為空
select * from t_hq_ryxx order by nianl + gongz;select nianl,gongz, (nianl + gongz) as g from t_hq_ryxx order by (nianl + gongz) desc;
--為字段的和定義別名,并以此為排序定義方式
select nianl,gongz, (nianl + gongz) as g from t_hq_ryxx order by g;select * from t_hq_ryxx;
--選擇bum為102或者103,性別為女的行
select * from t_hq_ryxx where (bum = '102' or bum = '103') and xingb = 2;
--選擇bum不為空的行
select * from t_hq_ryxx where bum is not null;--去重復
select distinct bum,xingb from t_hq_ryxx;--模糊查詢 % 通配符 _ 通配一位
select * from t_hq_ryxx where xingm like '%阿%';select * from t_hq_ryxx where bianh in ('101','103','105');select * from t_hq_ryxx where bianh = '101' or bianh = '103' or bianh = '105';select * from t_hq_ryxx where gongz between '1000' and '2000';select * from t_hq_ryxx where gongz >= 1000 and gongz <= 2000;--子查詢
select * from t_hq_ryxx where bum in (select bumenbm from t_hq_bm where lianxidh = '911');select * from t_hq_ryxx where gongz > all (select pingjgz from t_hq_bm);--分組-
select bum, count(1) as 數量 from t_hq_ryxx group by bum;select bum, count(1) as 數量,avg(gongz) as 平均值,sum(gongz) as 合計 from t_hq_ryxx group by bianh, bum;
--分組基礎上過濾
select bum, count(1) as 數量,avg(gongz) as 平均值,sum(gongz) as 合計 from t_hq_ryxx group by bum having avg(gongz) > 2000;select bum, count(1) as 數量,avg(gongz) as 平均值,sum(gongz) as 合計 from t_hq_ryxx where bum is not null group by bum having avg(gongz) > 2000;
?
轉載于:https://www.cnblogs.com/shadowduke/p/4915695.html
總結
以上是生活随笔為你收集整理的DQL查询语句内容整理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: samba and AD
- 下一篇: Google Closure Compl