请教个简单sql语句
表A
员工号 培训时间
1 2
2 4
3 6
4 3
5 1
6 1
表B
员工号 员工所属部门
1 办公室
2 办公室
3 客服
4 客服
5 开发
6 开发
要求最后查询出的结果:
部门 部门员工数 该部门员工参加培训的最少天数 该部门参加培训天数最少的人数
办公室 2 2 1
客服 2 3 1
开发 2 11
[解决办法]
select b.员工所属部门 部门 , min(a.培训时间) 该部门员工参加培训的最少天数from a,bwhere a.员工号=b.员工号
[解决办法]
create table A(id int,days int)create table B(id int,department varchar(50))insert into Aselect 1 , 2 union all select 2 , 4 union allselect 3 , 6 union allselect 4 , 3 union allselect 5 , 1 union allselect 6 , 1 insert into Bselect 1 , '办公室' union allselect 2 , '办公室' union allselect 3 , '客服' union allselect 4 , '客服' union allselect 5 , '开发' union allselect 6 , '开发' select B.department as '部门',count(A.id) as '部门员工数',min(A.days) as '该部门员工参加培训的最少天数'from A,B where A.id=B.id group by B.department