admin

此SQL查询有什么问题?

sql

以下查询返回“ ORA-00904错误:SATIS:无效的标识符”。当我删除该行时HAVING satis > 0,它可以工作。我该怎么办?

SELECT donem, bolge_adi, sehir_tasra "1=艦, 2=T", 
       COUNT(DISTINCT mekankodu) "M.SAYISI",
       SUM(b2b_dagitim + b2b_transfer - b2b_iade) satis
FROM mps_view2
WHERE donem IN ('200612','200712','200812','200912')
AND (ob IS NOT NULL OR b2b_ob IS NOT NULL)
GROUP BY donem, bolge_adi, sehir_tasra
HAVING satis > 0
ORDER BY donem, bolge_adi, sehir_tasra

阅读 193

收藏
2021-07-01

共1个答案

admin

您不能在条件中使用别名(查询的一部分)

试试这个:

SELECT donem, bolge_adi, sehir_tasra "1=艦, 2=T", 
   COUNT(DISTINCT mekankodu) "M.SAYISI",
   SUM(b2b_dagitim + b2b_transfer - b2b_iade) satis
FROM mps_view2
WHERE donem IN ('200612','200712','200812','200912')
      AND (ob IS NOT NULL OR b2b_ob IS NOT NULL)
GROUP BY donem, bolge_adi, sehir_tasra
HAVING SUM(b2b_dagitim + b2b_transfer - b2b_iade) > 0
ORDER BY donem, bolge_adi, sehir_tasra
2021-07-01