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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值