sql中sum,max,select,case when then 在一条语句中要怎样使用???
我要查的时间短时2014-04-01至2014-05-01但是有数据的最大的那一天是2014-04-02我要怎样才能这个语句selectmax(bdate)BDatefr...
我要查的时间短时2014-04-01至2014-05-01
但是有数据的最大的那一天是2014-04-02我要怎样才能
这个语句select max(bdate) BDate from Sdt_StatUserSubsidy_Table where typeid=999 and BDate BETWEEN '2014-04-01' AND '2014-05-01'能够查询到有只的最大那一天‘2014-04-02’
放到这里来来替换BDate所等于的值?
SUM(CASE WHEN W.TypeID = 999 AND BDate='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance
紧急求助!!!
其中SUM(CASE WHEN W.TypeID = 999 AND BDate='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance
中的BDate='2014-04-02' 的值不知道,是要查询出来的
查询语句是select max(bdate) BDate from Sdt_StatUserSubsidy_Table where typeid=999 and BDate BETWEEN '2014-04-01' AND '2014-05-01' 展开
但是有数据的最大的那一天是2014-04-02我要怎样才能
这个语句select max(bdate) BDate from Sdt_StatUserSubsidy_Table where typeid=999 and BDate BETWEEN '2014-04-01' AND '2014-05-01'能够查询到有只的最大那一天‘2014-04-02’
放到这里来来替换BDate所等于的值?
SUM(CASE WHEN W.TypeID = 999 AND BDate='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance
紧急求助!!!
其中SUM(CASE WHEN W.TypeID = 999 AND BDate='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance
中的BDate='2014-04-02' 的值不知道,是要查询出来的
查询语句是select max(bdate) BDate from Sdt_StatUserSubsidy_Table where typeid=999 and BDate BETWEEN '2014-04-01' AND '2014-05-01' 展开
1个回答
展开全部
是这个意思吗?
SUM(CASE WHEN W.TypeID = 999 AND (SUM(CASE WHEN W.TypeID = 999 AND BDate='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance)='2014-04-02' THEN BValue ELSE 0 end) as EndingBalance
请详细描述一下需求
更多追问追答
追答
1. 请贴文本
2. 请描述你的需求
试试这样:
SUM(CASE WHEN W.TypeID = 999 AND BDate=
(select max(bdate) BDate from Sdt_StatUserSubsidy_Table where typeid=999 and BDate BETWEEN '2014-04-01' AND '2014-05-01')
THEN BValue ELSE 0 end) as EndingBalance
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询