sql 分组查询 碰到的有关问题, 100结贴,恭候各位大神
sql 分组查询 碰到的问题,, 100结贴,恭候各位大神SQL[解决办法]SELECTsum(CASE WHEN N .[State] 入金成
sql 分组查询 碰到的问题,, 100结贴,恭候各位大神
SQL
[解决办法]SELECT sum(CASE WHEN N .[State] = '入金成功' THEN N .FundApplication ELSE 0 END) AS 入金总数,
sum(CASE WHEN N .[State] = '出金成功' THEN N .FundApplication ELSE 0 END) AS 出金总数
FROM dbo.NowApplyForTb AS N group by n.state
[解决办法]SELECT
SUM(CASE WHEN N .[State] = '入金成功' THEN isnull(N .FundApplication, 0 ELSE 0 END) AS 入金总数,
SUM(CASE WHEN N .[State] = '出金成功' THEN isnull(N .FundApplication, 0) ELSE 0 END) AS 出金总数
FROM dbo.NowApplyForTb AS N group by n.state
把SUM放到外面
[解决办法]select (select sum(FundApplication) from Nowapplyfortb where state='入金成功') as '入金总数' ,
(select sum(FundApplication) from Nowapplyfortb where state='出金成功') as '出金总数'
这样查出来的就只有一行,, 应该是你要的