日期:2014-05-17 浏览次数:20613 次
这个? SELECT NAME,NUM+NUM/(SELECT SUM(NUM) FROM ABC where NUM>0)*(SELECT SUM(NUM) FROM ABC where NUM<0) FROM ABC
------解决方案--------------------
--> 测试数据:[tb] IF OBJECT_ID('[tb]') IS NOT NULL DROP TABLE [tb] GO CREATE TABLE [tb]([细类] VARCHAR(1),[金额] INT) INSERT [tb] SELECT 'A',400 UNION ALL SELECT 'B',-100 UNION ALL SELECT 'C',-200 UNION ALL SELECT 'D',500 --------------开始查询-------------------------- SELECT [细类],[金额]+[金额]*1.0/(SELECT SUM([金额]) FROM [tb] WHERE [金额]>0)*(SELECT SUM([金额]) FROM [tb] WHERE [金额]<0) FROM [tb] WHERE [金额]>0 ----------------结果---------------------------- /* 细类 (无列名) A 266.666666666800 D 333.333333333500*/