求高手写一个视图

来源:百度知道 编辑:UC知道 时间:2024/06/02 23:54:22
实现这样
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

Create View bb(nd,deptid,xmid,nmoney)
as
select distinct c.* from (
select nd,deptid,min(xmid) as xmid , sum(nmoney) as nmoney from test
group by nd,deptid,left(xmid,4)
union all
select * from test where len(xmid)>4
) c

说明:test 为表名 ,我把你的money字段改成了nmoney
就这么多,我自己也测试过了,可以用!