Say a column is:
Price
$3.00
$3.00
The min and max would be equal. Is there a way to check for that in the WHERE clause?
Say a column is:
Price
$3.00
$3.00
The min and max would be equal. Is there a way to check for that in the WHERE clause?
There is a hundred years old HAVING
for filtering by aggregates.
SELECT 1
FROM YOUR_TABLE
HAVING MAX(PRICE) = MIN(PRICE)
WITH t(price) AS ( VALUES
(3.00),
(3.00)
)
SELECT
CASE
WHEN max(price) = min(price) THEN TRUE
ELSE FALSE
END
FROM t;
This is a way of doing that in MS SQL, I guess that should help you for Postgres somehow:
IF EXISTS (SELECT NULL FROM Table HAVING MAX(Price) = MIN(Price))
PRINT 'Equal'
ELSE
PRINT 'Not equal'
Another way inspired in Dmitry's answer:
IF ((SELECT CASE WHEN MAX(Price) = MIN(Price) THEN 1 END FROM Table) = 1)
PRINT 'Equal'
ELSE
PRINT 'Not equal'