1 select * from t_hq_ryxx;
2
3 select nianl, xingm from t_hq_ryxx;
4
5 select nianl as 年龄, xingm as 姓名 from t_hq_ryxx t;
6
7 select nianl 年龄 from t_hq_ryxx;
8
9 select nianl || xingm as 年龄和姓名 from t_hq_ryxx;
10
11 select nianl as hhh,t.* from t_hq_ryxx t order by nianl desc ;--排序
12
13 select nianl as hhh,t.* from t_hq_ryxx t order by xingb desc ,bum desc;
14
15 select nianl,xingm,bum,xingb from t_hq_ryxx t order by bum desc nulls last,xingb;
16
17 select * from t_hq_ryxx order by 3;
18
19 select nianl,gongz, (nianl+gongz)as g from t_hq_ryxx order by (gongz||nianl);
20
21 --去重复
22 select distinct bum from t_hq_ryxx;
23
24 select distinct bum,xingb from t_hq_ryxx;
25
26 select * from t_hq_ryxx;
27
28
29 select * from t_hq_ryxx where xingb = '1 'and bum = '102';
30
31 select * from t_hq_ryxx where (bum = '101' or bum = '102') and xingb = '2'and nianl >'40' ;
32
33 select * from t_hq_ryxx where bum is not null;
34
35 --模糊查询 %表示通配符
36
37 select * from t_hq_ryxx where xingm like '三%'
38
39 select * from t_hq_ryxx where xingm like '%儿'
40
41 select * from t_hq_ryxx where xingm like '%三%'
42
43 select * from t_hq_ryxx where gongz <any (select pingjgz from t_hq_bm);
44
45 --值得范围
46 select * from t_hq_ryxx where nianl in ('33','58');
47
48 select * from t_hq_ryxx where nianl ='33' or nianl = '58';
49
50 --区间范围
51
52 select * from t_hq_ryxx where gongz between 40 and 100;
53
54 select * from t_hq_ryxx where gongz >=40 and gongz <= 100;
55
56 --子查询
57 select * from t_hq_ryxx where bum in (select bumbm from t_hq_bm where lianxdh = '10086');
58
59 --大于最小值,小于最大值
60
61 select * from t_hq_ryxx where gongz >any (select pingjgz from t_hq_bm);
62
63 --大于最大值,小于最小值
64
65
66 select * from t_hq_ryxx where gongz >all (select pingjgz from t_hq_bm);
67
68 --分组 多种形式
69 select bum from t_hq_ryxx group by bum;
70
71 select bum,count(1) as 数量 from t_hq_ryxx group by bum;
72
73 select bum,count(1) as 数量,sum (gongz) as 合计 from t_hq_ryxx group by bum;
74
75 select bum,count(1) as 数量,avg(gongz) as 平均值 from t_hq_ryxx group by bum;
76
77 select nianl, bum,count(1) as 数量,avg(gongz) as 平均值 from t_hq_ryxx group by nianl, bum;
78
79 select bum,count(1) as 数量,avg(gongz) as 平均值 from t_hq_ryxx group by bum having avg(gongz)>60;
80
81
82