面试题:sql实现,根据table1,table2得出table3

提醒:题目中提供的table3有部分结果是错误的,请注意。


CREATE TABLE table1(mon varchar(100),dep varchar(100),yj int)
insert into table1
select '一月份','01',10
union all
select '一月份','02',10
union all
select '一月份','03',5
union all
select '二月份','02',8
union all
select '二月份','04',9
union all
select '三月份','03',8



CREATE TABLE table2(dep varchar(100),dname varchar(100))
insert into table2
select '01','国内业务一部'
union all
select '02','国内业务二部'
union all
select '03','国内业务三部'
union all
select '04','国内业务部'


select * from table1
select * from table2


select a.dep,
'一月份'=(select yj from table1 b where b.dep=a.dep and b.mon='一月份'),
'二月份'=(select yj from table1 b where b.dep=a.dep and b.mon='二月份'),
'三月份'=(select yj from table1 b where b.dep=a.dep and b.mon='三月份') 
from table2 a



drop table table1,table2


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值