gorpe
gorpe

Reputation: 25

how can I make more than 1 max?

I want to know how can I make 2 max

Upvotes: 0

Views: 49

Answers (2)

The Impaler
The Impaler

Reputation: 48865

Since you don't say which database you are using, I will assume it's PostgreSQL.

You may be looking for GREATEST(). For example:

select greatest(product1, product2, product3) from t;

Result:

greatest
--------
9
8
10

See example at db<>fiddle.

Upvotes: 1

Monofuse
Monofuse

Reputation: 827

First let me thank you for a different question, it actually had me thinking.

Assuming tsql:

DECLARE @data TABLE (id INT, num1 INT, num2 INT, num3 INT)

INSERT INTO @data
VALUES (1, 25, 36, 56), (2, 75, 43, 64)

SELECT max(pivotvals.val)
FROM @data d
CROSS APPLY (
    VALUES (d.num1), (d.num2), (d.num3)
) AS pivotvals (val)

result: 75

Upvotes: 0

Related Questions