0
を照会します。は、サブの複数の和の列を取得し、このクエリから
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」状態の合計を取得することはできません。私が結果として持っているのは、私の2つの列が空であることだけです。前もって感謝します。
どのように合計列を取得しようとしましたか? –
'table2'の意義は何ですか?このクエリでは使用されません。なぜあなたはそれが必要なのですか?また、 'Where'節の' OR'文の周りに '()'を置くべきです。 –