d*******n 发帖数: 524 | 1 We have a table (T_1) with e.g. 4 columns
T_1:
x y x z
1 2 3 4
3 6 1 -1
6 3 2 0
5 3 2 -10
I need a query to find out in each row which column has the max absolute value.
That is, I need to get the following table as output:
max_col
z
y
x
z
How to write this query in Oracle?
Thanks | a9 发帖数: 21638 | 2 有个旋转的关键字
sqlserver里是pivot
value.
【在 d*******n 的大作中提到】 : We have a table (T_1) with e.g. 4 columns : T_1: : x y x z : 1 2 3 4 : 3 6 1 -1 : 6 3 2 0 : 5 3 2 -10 : I need a query to find out in each row which column has the max absolute value. : That is, I need to get the following table as output: : max_col
| B*****g 发帖数: 34098 | 3 homework?suppose the 3rd cloumn x should be x1, suppose no dup max value in
a row
SELECT CASE GREATEST (ABS(x), ABS(y), ABS(x1), ABS(z))
WHEN ABS(x) THEN 'x'
WHEN ABS(y) THEN 'y'
WHEN ABS(x1) THEN 'x1'
ELSE 'z'
END CASE
FROM t_1
value.
【在 d*******n 的大作中提到】 : We have a table (T_1) with e.g. 4 columns : T_1: : x y x z : 1 2 3 4 : 3 6 1 -1 : 6 3 2 0 : 5 3 2 -10 : I need a query to find out in each row which column has the max absolute value. : That is, I need to get the following table as output: : max_col
| d*******n 发帖数: 524 | 4 Perfect! Thanks a lot!
Not for homework but work.
in
【在 B*****g 的大作中提到】 : homework?suppose the 3rd cloumn x should be x1, suppose no dup max value in : a row : SELECT CASE GREATEST (ABS(x), ABS(y), ABS(x1), ABS(z)) : WHEN ABS(x) THEN 'x' : WHEN ABS(y) THEN 'y' : WHEN ABS(x1) THEN 'x1' : ELSE 'z' : END CASE : FROM t_1 :
| d*******n 发帖数: 524 | 5 One more question. Is this exactly same as
SELECT
DECODE(GREATEST (ABS(x), ABS(y), ABS(x1), ABS(z)), ABS(x), 'x',
ABS(y), 'y',
ABS(x1), 'x1',
'z')
FROM
【在 B*****g 的大作中提到】 : homework?suppose the 3rd cloumn x should be x1, suppose no dup max value in : a row : SELECT CASE GREATEST (ABS(x), ABS(y), ABS(x1), ABS(z)) : WHEN ABS(x) THEN 'x' : WHEN ABS(y) THEN 'y' : WHEN ABS(x1) THEN 'x1' : ELSE 'z' : END CASE : FROM t_1 :
| B*****g 发帖数: 34098 | 6 same.
value
【在 d*******n 的大作中提到】 : One more question. Is this exactly same as : SELECT : DECODE(GREATEST (ABS(x), ABS(y), ABS(x1), ABS(z)), ABS(x), 'x', : : ABS(y), 'y', : : ABS(x1), 'x1', : : 'z') : FROM
|
|