結果的部門我有一個表是這樣的:加入兩個子查詢,有一個領域:兩個子查詢
userid | trackid | path
123 70000 ad
123 NULL abc.com
123 NULL Apply
345 70001 Apply
345 70001 Apply
345 NULL Direct
345 NULL abc.com
345 NULL cdf.com
而且我想這樣的查詢。當path ='abc.com'時,num_website +1;當路徑= '應用',num_apply +1
userid | num_website | num_Apply | num_website/num_Apply
123 1 1 1
345 1 2 0.5
我的語法如下:
select * from
(select userid,count(path) as is_CWS
from TABLE
where path='abc.com'
group by userid
having count(path)>1) a1
JOIN
(select userid,count(userid) as Apply_num from
where trackid is not NULL
group by userid) a2
on a1.userid=a2.userid
我的問題是 1.如何讓外地num_website/num_apply在我的語法項以上? 2.是否有其他更簡單的方法來獲得我想要的結果?
任何分享的景點都會很感激。
什麼是列別名「is_CWS」?或者它是num_website? where子句「track_id不爲空」適用於查詢的頂部(別名爲a1)?看看我的查詢有什麼不同 – objectNotFound
你沒有主鍵。這可能會在適當的時候證明問題 – Strawberry