在JOIN语句中使用MAX(Using MAX in a JOIN statement)
我试图返回不同域名的最大人员数量,但已经撞墙了。 我已经用human_hits回退了不同的域,但它只抓住了第一个域,所以它不是最大值。
我尝试将MAX添加到语句并进行实验,但只是设法挂起数据库。
这是我到目前为止所拥有的......
SELECT q.* FROM ( SELECT ah.datestamp, ad.domain, ah.human_hits FROM `a_hits_hourly` ah INNER JOIN a_saved_domains ad ON ah.domain_id = ad.domain_id WHERE ah.datestamp > 2016070000 AND ah.human_hits > 0 ) q GROUP BY q.domain有人可以帮忙吗?
谢谢
史蒂夫
I'm trying to return the max human_hits of distinct domains but have hit a wall. The statement I have pulls back distinct domains with human_hits, but it just grabs the first one, so it's not the max.
I tried adding MAX to the statement and experimenting but only managed to hang the database.
Here's what I have so far...
SELECT q.* FROM ( SELECT ah.datestamp, ad.domain, ah.human_hits FROM `a_hits_hourly` ah INNER JOIN a_saved_domains ad ON ah.domain_id = ad.domain_id WHERE ah.datestamp > 2016070000 AND ah.human_hits > 0 ) q GROUP BY q.domainCan anybody help?
Thanks
Steve
最满意答案
那这个呢?
SELECT ad.domain, MAX(ah.human_hits) FROM `a_hits_hourly` ah INNER JOIN a_saved_domains ad ON ah.domain_id = ad.domain_id WHERE ah.datestamp > 2016070000 AND ah.human_hits > 0 GROUP BY ad.domain它应该为您获得每个domain的最大human_hits 。 或者也许我不确定你想要什么。
What about this?
SELECT ad.domain, MAX(ah.human_hits) FROM `a_hits_hourly` ah INNER JOIN a_saved_domains ad ON ah.domain_id = ad.domain_id WHERE ah.datestamp > 2016070000 AND ah.human_hits > 0 GROUP BY ad.domainIt should get you the maximum human_hits for each domain. Or perhaps I'm not sure what you are wanting.
更多推荐
发布评论