DQL数据查询语言
--查询全表
select * from t_hq_ryxx;
--查询字段
select xingm as 姓名 ,gongz as 工资 from t_hq_ryxx;
--链接字段查询
select xingm || xingb as 姓名性别 from t_hq_ryxx
--去除重复查询
select distinct bumbm from t_hq_ryxx;
--排序查询 desc 降序 asc升序
select * from t_hq_ryxx order by bumbm desc;
--组合排序查询 nulls first 空值排序在前 nulls last 空值排序在后
select bumbm as 部门编码,t.* from t_hq_ryxx t order by xingb desc,bumbm
nulls first;
--数字代表字段列表序号
select * from t_hq_ryxx order by 4;
--组合、表达式排序查询
select * from t_hq_ryxx order by xingm || xingb;
--where条件查询
select * from t_hq_ryxx where xingb = 1 and bumbm = 103;
select * from t_hq_ryxx where bumbm is not null;
select * from t_hq_ryxx where bumbm in (103,104,106);
select * from t_hq_ryxx where gongz between 3000 and 4000;
--模糊查询 % 任意位数通配符 _ 一位通配符
select * from t_hq_ryxx where xingm like '%s%'
select * from t_hq_ryxx where xingm like 'a_d'
--子查询
select * from t_hq_ryxx where bumbm in (select bumbm from t_hq_bm where dianh
= '10086');
--分组查询 group by 配合 having使用,进行过滤
select bumbm,count(1) as 数量 , avg(gongz) as 平均工资 from t_hq_ryxx group by bumbm having avg(gongz)> 4000;