SELECT SUM(MONEY) AS TOTAL FROM
(SELECT CARD,CASE WHEN CARD IS NULL THEN 25 WHEN CARD IS NOT NULL THEN 5 END AS MONEY
FROM TABLE1)TABLE2
卡号会重复不?
有个比较笨的方法
select
(select COUNT(card) from dbo.Table_1 ) AS '总人数',
(select COUNT(card) from dbo.Table_1 where card is null ) as '人数1',
(select COUNT(card) from dbo.Table_1 where card is not null ) as '人数2'
卡号重复没关系,我现在主要纠结的是判断卡号空值为25和卡号不空值为5的问题,最后还要把这两个值的最后结果加在一起。
@狮女小熊:
SELECT SUM(MONEY) AS TOTAL FROM
(SELECT CARD,CASE WHEN CARD IS NULL THEN 25 WHEN CARD IS NOT NULL THEN 5 END AS MONEY
FROM TABLE1)TABLE2
@念念啊: 这样把所有的都求和了吧。 是不是还要有一个group by ...
@天生俪姿: 她说的是把2个值得最后结果加起来,如果分别求和的话就用GROUP BY
@念念啊: 嗯 我觉得另一种 有两个东西。。 一个是Group by 一个是列转行。。 如果是SQLserver2005 就好办点。。
楼的可以实现但效率低了点
你有什么更好的方法么