sql语句在线练习

有没有在线SQL语句查询练习的平台

在线的我倒不知道,不过我知道用新浪sae随便创建个应用(php的,免费),然后你就可以免费用里面的云数据库了,当然也可以在线练习sql语句了。顺便说一句,选应用仓库千万不要选git,新浪的git仓库是巨坑啊!!当初我不小心选了git仓库,现在吐血中。。

请朋友们帮忙写出SQL语句.感谢!在线等!!

–建立测试数据
create table tb
(姓名 varchar(20) null,
费用类型 varchar(20) null,
费用金额 decimal null
)
go
insert into tb
select ’XM1’,’交通费’,50
union all
select ’XM1’,’交通费’,40
union all
select ’XM1’,’餐饮费’,60
union all
select ’XM1’,’餐饮费’,60
union all
select ’XM1’,’办公费’,30
union all
select ’XM1’,’办公费’,30
union all
select ’XM2’,’办公费’,30
union all
select ’XM2’,’办公费’,60
go
–查询语句
declare @sql varchar(8000)
set @sql = ’select 姓名 ’
select @sql = @sql + ’ , sum(case 费用类型 when ’’’ +费用类型+ ’’’ then 费用金额 else 0 end) [’ + 费用类型 + ’]’
from (select distinct 费用类型 from tb) as a
set @sql = @sql + ’ from tb group by 姓名’
–print (@sql)
exec(@sql)
——————–结果集——————————
姓名 办公费 餐饮费 交通费
——————– —————————————- —————————————- —————————————-
XM1 60 120 90
XM2 90 0 0
–删除测试数据
drop table tb