3

我想要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
4

1 回答 1

3

Use having,它是一个where应用 after 而不是 before 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
于 2013-03-02T08:11:12.523 回答