在JOIN语句中使用MAX(Using MAX in a JOIN statement)

编程入门 行业动态 更新时间:2024-10-28 18:34:38
在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.domain

Can 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.domain

It should get you the maximum human_hits for each domain. Or perhaps I'm not sure what you are wanting.

更多推荐

本文发布于:2023-07-22 12:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   JOIN   statement   MAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!