我想CASE STHAR_GCKOD when 'G' THEN STHAR_GCMIK >=1
所以我不想要null或0
这可能吗 ?谢谢..
SELECT
STOK_KODU,
SUM(CASE STHAR_GCKOD WHEN 'G' THEN STHAR_GCMIK ELSE 0 END) // INCOMING,
SUM(CASE STHAR_GCKOD WHEN 'C' THEN STHAR_GCMIK ELSE 0 END) // OUTGOING,
SUM(CASE STHAR_GCKOD WHEN 'G' THEN STHAR_GCMIK ELSE -STHAR_GCMIK END) // TOTAL
FROM
STOKCEK
GROUP BY
STOK_KODU
答案 0 :(得分:3)
使用having
,而不是在where
之前应用group by
:
Select STOK_KODU,
sum(CASE STHAR_GCKOD WHEN 'G' THEN STHAR_GCMIK ELSE -STHAR_GCMIK end)
FROM STOKCEK
GROUP BY STOK_KODU
having sum(CASE STHAR_GCKOD WHEN 'G' THEN STHAR_GCMIK ELSE -STHAR_GCMIK end) > 0