场景查询
Query for the scenario
我必须执行一个如下所示的查询;
Col_1 Col_2 Col_3 Col_4 Col_5
A AB AC AD AE
B BC BD BE ?
C CD CE ? ?
D DE ? ? ?
E ? ? ? ?
非常感谢对以下内容的任何帮助。
谢谢,
阿米特
{
SELECT CHR(64+LEVEL) AS A,
DECODE(SIGN( 4 - LEVEL ) , -1, '?',CHR(64+LEVEL)||CHR(65 +LEVEL)) B,
DECODE(SIGN( 3 - LEVEL ) , -1, '?',CHR(64+LEVEL)||CHR(66 +LEVEL)) C,
DECODE(SIGN( 2 - LEVEL ) , -1, '?',CHR(64+LEVEL)||CHR(67 +LEVEL)) D,
DECODE(sign( 1 - level ) , -1, '?',chr(64+level)||chr(68 +level)) E
from dual connect by level <6;
}
以上是使用oracle 10g,其他db应该有其他策略。
每列需要不同的rows
:
select
col_1
,col_1 || min(col_1) over (order by ... rows between 1 following and 1 following)
,col_1 || min(col_1) over (order by ... rows between 2 following and 2 following)
,col_1 || min(col_1) over (order by ... rows between 3 following and 3 following)
,col_1 || min(col_1) over (order by ... rows between 4 following and 4 following)
我必须执行一个如下所示的查询;
Col_1 Col_2 Col_3 Col_4 Col_5
A AB AC AD AE
B BC BD BE ?
C CD CE ? ?
D DE ? ? ?
E ? ? ? ?
非常感谢对以下内容的任何帮助。
谢谢, 阿米特
{
SELECT CHR(64+LEVEL) AS A,
DECODE(SIGN( 4 - LEVEL ) , -1, '?',CHR(64+LEVEL)||CHR(65 +LEVEL)) B,
DECODE(SIGN( 3 - LEVEL ) , -1, '?',CHR(64+LEVEL)||CHR(66 +LEVEL)) C,
DECODE(SIGN( 2 - LEVEL ) , -1, '?',CHR(64+LEVEL)||CHR(67 +LEVEL)) D,
DECODE(sign( 1 - level ) , -1, '?',chr(64+level)||chr(68 +level)) E
from dual connect by level <6;
} 以上是使用oracle 10g,其他db应该有其他策略。
每列需要不同的rows
:
select
col_1
,col_1 || min(col_1) over (order by ... rows between 1 following and 1 following)
,col_1 || min(col_1) over (order by ... rows between 2 following and 2 following)
,col_1 || min(col_1) over (order by ... rows between 3 following and 3 following)
,col_1 || min(col_1) over (order by ... rows between 4 following and 4 following)