【发布时间】:2017-01-19 16:21:05
【问题描述】:
从这个查询:
select LastStateS='LastStateS1and2'
, count(s.LastState) as sumS,
LasteStateE='LastStateE1and2'
, count(e.LastState) as sumE
from table1 t1
join table2 t2
on t1.ID = t2.ID
join (select LastState
,count(LastState) as sum
from table1
where ID = X
and LastState = 1
or LastState = 2
group by LastState
) s
on s.LastState = t1.LastState
join (select LastState
,count(LastState) as sum
from table1
where ID = X
and LastState = 3
or LastState = 4
group by LastState
) e
on e.LastState = t1.LastState
我无法检索我的“laststate”条件的总和。结果我的两列都是空的。提前致谢。
【问题讨论】:
-
您是如何尝试检索总和列的?
-
table2的意义是什么?此查询中未使用它。你为什么需要它?此外,您应该在Where子句中的OR语句周围加上()。
标签: sql sql-server reporting-services