簡體   English   中英

SQL子選擇語句使用where子句進行過濾

[英]SQL Sub-select statements filter using where clause

我正在構建一個儀表板,需要從一個稍微復雜的模式中提取一些數據。

我有一個用於提取信息的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”的嵌套選擇語句上放置一個過濾器,但是當我嘗試它時似乎不起作用。 我讀過一些博客說這是不可能的,所以我有些困惑。

任何幫助將非常感激。

謝謝。

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....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM