不能在sqlite中将两个语句组合成一个语句?

时间:2012-11-10 09:10:20

标签: sqlite

声明1:

create table tmp as  select code  , round((max(close)-min(close))/min(close),2) as volatility,
    case  when  (max(close)-min(close))/min(close) <0.1  then  "grade1" 
    when  (max(close)-min(close))/min(close)       <0.2  then  "grade2"
    when  (max(close)-min(close))/min(close)       <0.3  then  "grade3"
    else "grade4"  end  as  type
    from  quote  where date between '20120801' and '20121101' and code<'07000'  
    group by code order by volatility ;

声明2:

select  tmp.code,profile.name, tmp.volatility from tmp,profile where tmp.code=profile.code;

语句1和语句2可以运行,当我将两者合二为一时 - 语句3, 它不能运行,是什么事?

声明3:

 select quote.code ,profile.name, round((max(quote.close)-min(quote.close))/min(quote.close),2) as quote.volatility,
    case  when  (max(quote.close)-min(quote.close))/min(quote.close) <0.1  then  "grade1" 
    when  (max(quote.close)-min(quote.close))/min(quote.close)       <0.2  then  "grade2"
    when  (max(quote.close)-min(quote.close))/min(quote.close)       <0.3  then  "grade3"
    else "grade4"  end  as  quote.type
    from  quote,profile where quote.date between '20120801' and '20121101' and quote.code<'07000' and quote.code=profile.code
    group by quote.code order by quote.volatility ;

1 个答案:

答案 0 :(得分:0)

只需将您的第一个语句作为子查询:

select tmp.code, profile.name, tmp.volatility
from (select code,
             round(...) as volatility,
             case ... end as type
      from quote
      where date between '20120801' and '20121101'
        and code<'07000'
      group by code
      order by volatility) as tmp,
     profile
where tmp.code = profile.code;
相关问题