2016-12-07 45 views
0

我有以下内容,并且我试图从AS部分中的“id_category”中获取值。我需要把它引用到内置的链接越往下查询如何从选择“as”获取值

case 
    when pa.category_id = 310 then 669 -- Trains 
    when pa.category_id = 309 then 2785 -- Ships 
    when pa.category_id = 311 then 631 -- Planes 
    end 
     else concat("NOT FOUND FOR ",pc.name) 
    end **as "id_category",** 

回答

0

您将获得它在外部查询像

select id_category, ... 
from (
select case 
    when pa.category_id = 310 then 669 -- Trains 
    when pa.category_id = 309 then 2785 -- Ships 
    when pa.category_id = 311 then 631 -- Planes 
     else concat("NOT FOUND FOR ",pc.name) 
    end as "id_category" from table1) xxx; 
0

你只能我们在为了通过的id_category声明。如果您想在其他地方使用它,请尝试使用子查询

Select SUBQUERY.id_category 
from (select 

case 
    when pa.category_id = 310 then 669 -- Trains 
    when pa.category_id = 309 then 2785 -- Ships 
    when pa.category_id = 311 then 631 -- Planes 
    end 
     else concat("NOT FOUND FOR ",pc.name) 
    end **as "id_category",** 
... 
) AS 'SUBQUERY' 
...