由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - How to write this query in Oracle?
相关主题
Help on Oracle QueryHow to write this loop SQL query?
One sql question help!oracle和XML
ask for help with a simple query!!!需要帮助 -- Oracle Query
a sql questionOracle,table有上千个column
Is there such a thing as "limited writing access" in Oracle database server菜鸟请教一个关于oracle里日期的问题
这个 Oracle SQL 语句该这么写啊?A sql question
how to write this queryOracle Group and Index question
大家帮忙看看这个oracle statement, 怎么总是报错?初级问题
相关话题的讨论汇总
话题: abs话题: oracle话题: x1话题: query话题: write
进入Database版参与讨论
1 (共1页)
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

1 (共1页)
进入Database版参与讨论
相关主题
初级问题Is there such a thing as "limited writing access" in Oracle database server
[转载] Can anyone interpret this simple SQL?这个 Oracle SQL 语句该这么写啊?
Re: 请问怎么在QUERY出来的结果里第一列加上自己的INCREMENTALhow to write this query
请教sqlserver怎么能capture query?大家帮忙看看这个oracle statement, 怎么总是报错?
Help on Oracle QueryHow to write this loop SQL query?
One sql question help!oracle和XML
ask for help with a simple query!!!需要帮助 -- Oracle Query
a sql questionOracle,table有上千个column
相关话题的讨论汇总
话题: abs话题: oracle话题: x1话题: query话题: write