如何在teradata中逐级转换

时间:2011-11-17 18:30:42

标签: sql oracle case teradata connect-by

我试图将oracle的连接级别函数转换为teradata。我在网上看过很多例子,但这个例子不同,

 (SELECT 
     CASE LEVEL 
        WHEN 1 THEN 'MB'
        WHEN 2 THEN 'SB'
        ELSE 'TOTAL'
     END AS DRUG_SOURCE
 FROM
    DUAL 
 CONNECT BY LEVEL <= 3) RW  

如果你们有任何想法,请告诉我。

2 个答案:

答案 0 :(得分:1)

嘿,我找到了解决方法。对不起,我无法清楚地解释我的问题。

下面的代码将完全按照我想要的方式在teradata中运行

select 'MB' as DRUG_SOURCE from dual  
union  
select 'SB' as DRUG_SOURCE from dual  
Union  
select 'TOTAL' as DRUG_SOURCE from dual  

答案 1 :(得分:0)

您可以尝试以下代码:

select DRUG_SOURCE from (select 'MB' as DRUG_SOURCE,1 as id) a
union all
select DRUG_SOURCE from (select 'SB' as DRUG_SOURCE,2 as id) b
union all
select DRUG_SOURCE from (select 'TOTAL' as DRUG_SOURCE,3 as id) c