我有兩個查詢。一:聯合兩個查詢PostgreSQL
select driver_id,count(*) as minors from zendesk_tickets
where city = 'Los Angeles'
and (tags like '%la_driver_quality_inefficientroute%'
or tags like '%la_driver_quality_attitude%'
or tags like '%la_driver_quality_dirtycar%'
or tags like '%la_driver_quality_hygiene%'
or tags like '%la_driver_quality_wronguser%'
or tags like '%la_driver_quality_starttripearly%'
or tags like '%la_driver_quality_arrivingearly%'
or tags like '%la_driver_quality_didnotanswer%'
or tags like '%la_driver_quality_nodoor%'
or tags like '%la_driver_quality_cigarettes%'
or tags like '%la_driver_quality_startstop%'
or tags like '%la_driver_quality_arguing%'
or tags like '%la_driver_quality_refusedestination%'
or tags like '%la_driver_quality_onphoneontrip%'
)
and driver_id is not null
group by driver_id
order by minors desc
,輸出:
driver_id minors
1234 2
1243 3
etc etc
而另一查詢:
select driver_id,count(*) as majors from zendesk_tickets
where city = 'Los Angeles'
and (tags like '%la_driver_quality_acceptcash%'
or tags like '%la_driver_quality_solicitingclient%'
or tags like '%la_driver_quality_majordisrespect%'
or tags like '%la_driver_quality_physicalaltercation%'
or tags like '%la_driver_quality_sexualharassment%'
or tags like '%la_driver_quality_majordrivingviolation%'
or tags like '%la_driver_quality_dui%'
or tags like '%la_driver_quality_usingaccount%'
or tags like '%la_driver_quality_expiredinfo%'
)
and driver_id is not null
group by driver_id
order by majors desc
,輸出:
driver_id majors
1234 1
1243 2
etc etc
當我嘗試加入這兩個(左連接)它仍然只返回驅動程序id在第一個查詢中(未成年人)。我想基本上結合這些查詢,但聯合函數不在我的查詢生成器中工作。關於如何提高這兩個查詢的結構和所有未成年人和專業的數據恢復到一個表的任何建議將輸出:
driver_id minors majors
1234 1 3
1243 2 4
etc etc etc.
「whyn我嘗試加入這兩個「......怎麼樣?請顯示組合查詢。此外,你正在使用什麼「查詢構建器」? –
「聯盟」與您所描述的不同。 – pstanton