SELECT
T . ID,
T . NAME,
T .feed_id,
T .status,
T .budget,
(
SELECT
COUNT (*)
FROM
segment
WHERE
segment.campaign_id = T . ID
) AS total_segments,
(
SELECT
SUM (revenue)
FROM
TRANSACTION
WHERE
TRANSACTION .campaign_id = T . ID
AND TRANSACTION .status = 3
AND deleted = 0
) AS projected_revenue
FROM
campaign T
WHERE
(T .deleted = 0)
AND (site_id = 3)
GROUP BY
T ."id"
HAVING
(
SELECT
SUM (revenue)
FROM
TRANSACTION
WHERE
TRANSACTION .campaign_id = T . ID
AND TRANSACTION .status = 3
AND deleted = 0
) > 242.45
ORDER BY
T . ID DESC
查詢怪異的結果正常工作時having
子查詢比(>
)大於或小於(<
),但等於當它不顯示任何結果。但它的工作原理:對PostgreSQL的having子句
HAVING (
SELECT SUM (revenue)
FROM TRANSACTION
WHERE TRANSACTION.campaign_id = T.ID
AND TRANSACTION.status = 3
AND deleted = 0
)::NUMERIC = 242.45
是否可以通過NUMERIC類型說明符在較小的時間間隔內進行比較? ('242.45'不能表示爲有限的二進制數。) –
@GáborBakos'NUMERIC'是二進制編碼的十進制數。 –