MSSQL转Sybase问题
实现这样
nd deptid xmid money
2008 001000000 j001 220.00
2008 001060000 g004 65.00
2008 001060000 j006 45.00
2008 001060000 j001 6.00//这个加下面的
2008 001060000 j00101 34.00
如果xmid的前四位、deptid、nd相同的则sum(money)
上表实现这样的
nd deptid xmid money
2008 001000000 j001 220.00
2008 001060000 g004 65.00
2008 001060000 j006 45.00
2008 001060000 j001 40.00//变成这个
2008 001060000 j00101 34.00
MSSQL里面通过
declare @tb table( nd varchar(4), deptid varchar(9), xmid varchar(10), money decimal(18,2) )
insert into @tb select '2008', '001000000', 'j001', 220.00
insert into @tb select '2008', '001060000', 'g004', 65.00
insert into @tb select '2008', '001060000', 'j006', 45.00
insert into @tb select '2008', '001060000', 'j001', 6.00
insert into @tb select '2008', '001060000', 'j00101', 34.00
select a.nd, a.deptid,a.xmid,
( select sum(b.money) from @tb b where b.nd = a.nd and b.deptid = a.deptid and b.xmid like a.xmid + '%' ) as money
from
(
select nd, deptid,xmid,sum(money) as money
from @tb
group by nd, deptid, xmid
) a
/*结果
nd deptid xmid money
---- --------- ---------- ----------------------------------------
2008 001000000 j001 220.00
2008 001060000 g004 65.00
2008 001060000 j001 40.00
2008 001060000 j00101 34.00
2008 001060000 j006 45.00
*/
请问在SBYASE里面怎么改呢?
谢谢
------------------------------------------------
CREATE VIEW dbo.viem_yszcmx
( nd,
deptid,
xmid,
ysmoney ) AS
select a.nd,
a.deptid,
a.xmid,
( select sum(b.money)
from yszcmx , b
where b.nd = a.nd and
b.deptid = a.deptid and
b.xmid like a.xmid + '%' ) as money
from
(
select yszcmx.nd,
yszcmx.deptid,
yszcmx.xmid,
sum(money) as money
from yszcmx
WHERE ( yszcmx.shzt <> '2' ) AND
( yszcmx.xzzt <> '2' )
group by yszcmx.nd,
yszcmx.deptid,
yszcmx.xmid
) a
求高人改成sybase11能用的视图代码!!!
谢谢了
补充:视图转换问题
答案:SELECT t3.nd,t3.deptid,mid(t3.xmid,1,4) as xmid ,sum(t3.money) as Xmoney
FROM t3 group by t3.nd,t3.deptid,mid(t3.xmid,1,4)
标准语句在哪儿都可以执行
上一个:关于MSSQL中触发器的问题
下一个:怎样把MSSQL数据库还原到虚拟主机上啊