Home > database >  SQL can achieve the maximum column, how to seek the maximum
SQL can achieve the maximum column, how to seek the maximum

Time:10-21

A maximum of column well, now to how great god can make for the maximum value,

CodePudding user response:

Can be used as Max, he forgot whether to add a select, now no environment test

CodePudding user response:


To help you correct migraine,

CodePudding user response:

 USE tempdb for 
GO
IF OBJECT_ID (' t ') IS NOT NULL
DROP TABLE t
GO
CREATE TABLE (t
[key] VARCHAR (10),
INT x,
Y INT,
Z INT
)
INSERT INTO t VALUES (' A ', 1, 2, 3);
INSERT INTO t VALUES (' B ', 5,5,2);
INSERT INTO t VALUES (' C ', 4,7,1);
INSERT INTO t VALUES (' D ', three filling);
-- -- -- -- -- - above for testing table and test data -- -- -- -- -- -- --

SELECT [key]
That CASE WHEN x> THEN x ELSE y y END AS greatest
That CASE WHEN x>=y AND x>=z THEN x
The WHEN y>=x AND y> THEN y=z
The ELSE z END AS greatest_3_col
The FROM t;
/*
The key greatest greatest_3_col
A, 2, 3,
5 5 B
7 7 C
3 3 D
*/

CodePudding user response:

Here are used in the row in the column the method of maximum sharing http://www.maomao365.com/? P=9946
  • Related