2012-10-24 118 views
2

我正在构建仪表板并需要从一个稍微复杂的模式中提取一些数据。SQL子选择语句筛选器使用where子句

我有一个select语句(见下文),我用它来提取信息,但需要对select语句的一部分进行一些过滤,而且我正在挣扎。

select distinct j.id 'Job_Id' 
     , js.outcome 'Outcome' 
     ,(select string from property where parent_sheet_id = ps.id and name= 'Build_Type') as 'Build_Type' 
    from job j, job_step js, property_sheet ps, property p 
    where j.id = js.job_id 
    and ps.entity_id=js.id 
    and ps.id=p.parent_sheet_id 
    and ps.entity_type='step' 
    and p.name = 'Id' 
    group by j.id 
    order by j.id desc; 

我相信有这样的查询的一种更好的方式,我将不胜感激任何其他建议,但我主要是试图将一个过滤器在具有Build_Type的”别名的嵌套查询语句“,但是当我尝试它似乎不工作。我读过一些博客,这是不可能的,所以我有点卡住了。

任何帮助将不胜感激。

谢谢。

回答

0
select 
ps.id, 
Build_Type.string 
from 
property_sheet as ps 
left join 
property as Build_Type 
on ps.id = Build_Type.parent_sheet_id and Build_Type.name = 'Build_Type' 

where Build_Type....