我正在PostgreSQL數據庫上寫一個查詢,並且不知道如何在連接後執行非空值的計數。在MySQL中我會寫:postgresql vs mysql左連接
select count(a.clicker_id), count(b.clicker_id) from
(select * from events where type='click') a
left join (select * from tbl_events where type='conversion')b
on a.clicker_id=b.clicker_id
基本上,試圖寫沒有一個子查詢如下:
select date(cl.created_at), count(cl.click_id) as clicks, count(cp.click_id) as Conversions from events_table cl
left outer join (select click_id, created_at from events_table where type='conversion_potential')cp
on (cl.click_id=cp.click_id)
where cl."type"='click'
and cl.placement_id in (1,2,3)
group by 1
由於你的'b.type = conversion'子句,你事實上正在做一個內部連接。仔細檢查你的MySQL查詢是否是你發佈的。 – 2013-05-07 12:18:48
剛剛刪除我的答案,因爲是錯的。 – fog 2013-05-07 12:35:42
在_RIGHT_查詢中是否真的有兩個表,事件和tbl_events? – 2013-05-07 13:05:36