SQL查询

mysql> create table t_worker(

-> department_id int(11) not null comment '部门号',

-> worker_id int(11) primary key not null comment '职工号',

-> worker_date date not null comment '工作时间',

-> wages float(8,2) not null comment '工资',

-> politics varchar(10) not null default '群众' comment '政治面貌',

-> name varchar(20) not null comment '姓名',

-> borth_date date not null comment '出生日期');

mysql> insert into t_worker values (101,1001,'2015-5-4',7500.00,'群众','张春燕','1990-7-1');

Query OK, 1 row affected (0.01 sec)

mysql> insert into t_worker values (101,1002,'2019-2-6',5200.00,'团员','李名博','19

97-2-8');

Query OK, 1 row affected (0.01 sec)

mysql> insert into t_worker values (102,1003,'2008-1-4',10500.00,'党员','王博涵','1

983-6-8');

Query OK, 1 row affected (0.01 sec)

mysql> insert into t_worker values (102,1004,'2016-10-10',5500.00,'群众','赵小军','

1994-9-5');

Query OK, 1 row affected (0.01 sec)

mysql> insert into t_worker values (102,1005,'2014-4-1',8800.00,'党员','钱有财','19

92-12-30');

Query OK, 1 row affected (0.01 sec)

mysql> insert into t_worker values (103,1006,'2019-5-5',5500.00,'党员','孙菲菲','19

96-9-2');

Query OK, 1 row affected (0.01 sec)

(1)mysql> select * from t_worker;

(2)mysql> select distinct department_id from t_worker;

(3)mysql> select count(1) from t_worker;

(4)mysql> select max(wages) , min(wages) from t_worker;

(5)mysql> select round(avg(wages),2),sum(wages) from t_worker;

(6)mysql> create table work_date(worker_id int(11) primary key not null comment'职工号',name varchar(20) not null comment'姓名', worker_date date not null comment'工作时间');

mysql> desc work_date;

(7)mysql> select year(now())-year( borth_date) from t_worker

-> where politics='党员';

(8)mysql> select name from t_worker

-> where wages between 4000 and 8000;

(9)mysql> select name from t_worker

-> where name like '孙%' or name like '李%';

(10)mysql> select worker_id,name from t_worker

-> where department_id in (102,103) and politics!='党员';

(11)mysql> select * from t_worker

-> order by borth_date ;

(12)mysql> select worker_id,name from t_worker order by wages desc limit 1,3;

(13)mysql> select count(1) from t_worker

-> where politics='党员';

(14)mysql> select sum(wages),round(avg(wages),2) from t_worker;

(15)mysql> select department_id,count(1) from t_worker

-> group by department_id

-> having count(1)>=3;

相关推荐
柯南二号6 分钟前
Task ‘wrapper‘ not found in project ‘:example‘. 报错解决
android·gradle·hippy
我又来搬代码了9 分钟前
【Android】项目升级时报错 android:style/Holo.Widget
android·gitee
洞见不一样的自己3 小时前
android 常用方法
android
暗碳3 小时前
华为麦芒5(安卓6)termux记录 使用ddns-go,alist
android·linux
m0_748252233 小时前
ADB在浏览器中的革命:ya-webadb项目解析及新手指南
adb
seven27293 小时前
Android MQTT关于断开连接disconnect报错原因
android·mqtt·disconnect报错
drebander6 小时前
SQL 实战:日期与时间函数 – 统计数据的时间跨度与趋势
linux·数据库·sql
winner88816 小时前
Hive SQL 之 `LATERAL VIEW EXPLODE` 的正确打开方式
hive·hadoop·sql·explode·lateral view·hive split
随猿Fa6 小时前
arthas查看拼接好参数的sql, redis, es完整可直接执行的命令
redis·sql·elasticsearch
Maplee7 小时前
Compose 转场动画之 Transition
android·前端