结果的部门我有一个表是这样的:加入两个子查询,有一个领域:两个子查询
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