日期:2014-05-18  浏览次数:20340 次

求高难道报表统计语句,高手请进来
tablea  
编码       费用类别     费用
23               1                 4
23               43               3
23               100             7
23               76               1
23               75               3
23               22               6
25               12                 54
25               4                 2
25               12               8
25               76               5
25               75               4
25               22               2


tableb
费用名称         费用类别
书本费               1,22,75,76
文具费               4,12,43,100

想出来报表
编码         费用名称         费用
23               书本费           14
23               文具费           10
25               书本费           11
25               文具费           64


请高手帮帮忙,tableb的费用类别就等于tabla   的费用类别.


------解决方案--------------------
/*创建测试数据*/
if object_id( 'tbTestA ') is not null
drop table tbTestA
if object_id( 'tbTestB ') is not null
drop table tbTestB
GO
create table tbTestA(编码 int, 费用类别 varchar(10), 费用 int)
insert tbTestA
select 23, 1, 4 union all
select 23, 43, 3 union all
select 23, 100, 7 union all
select 23, 76, 1 union all
select 23, 75, 3 union all
select 23, 22, 6 union all
select 25, 12, 54 union all
select 25, 4, 2 union all
select 25, 12, 8 union all
select 25, 76, 5 union all
select 25, 75, 4 union all
select 25, 22, 2

create table tbTestB(费用名称 varchar(50), 费用类别 varchar(50))
insert tbTestB
select '书本费 ', '1,22,75,76 ' union all
select '文具费 ', '4,12,43,100 '
GO

------解决方案--------------------
if object_id( 'pubs..tablea ') is not null
drop table tablea
go

create table tablea(编码 int,费用类别 varchar(10),费用 int)
insert into tablea (编码,费用类别,费用) values(23, '1 ' , 4)
insert into tablea (编码,费用类别,费用) values(23, '43 ' , 3)
insert into