内连接+计数+分组依据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了内连接+计数+分组依据相关的知识,希望对你有一定的参考价值。
我无法计算/分组内部联接的结果
我有两张桌子
results_dump
:有两列:email
和result
(结果值可以是open
或bounce
)all_data
:有三列:email
,full_name
和address
第一个目标是查询result_dump表,并对特定"open"
的结果为email
的次数进行计数和分组。
此查询效果很好:
SELECT `email`, COUNT(*) AS count
FROM `result_dump`
WHERE `date` = "open"
GROUP BY `email`
HAVING COUNT(*) > 3
ORDER BY count DESC
它取得这些结果的第二个目标(任何“打开”超过3次的人)并提取'full_name'和'地址',这样我就会详细了解谁开了3次以上的电子邮件。
我有这个问题,它可以将数据汇集在一起 - 但我无法弄清楚如何让COUNT
,HAVING
和ORDER
与INNER JOIN
一起工作?
SELECT *
FROM all_data
INNER JOIN result_dump ON
all_data.email = result_dump.email
where `result` = "open"
答案
SELECT email,name,count(*)
FROM all_data
INNER JOIN result_dump ON
all_data.email = result_dump.email
where `result` = "open"
group by result_dump.email
having count(*)>3
ORDER by count DESC
我认为这个没有错。
另一答案
尝试使用以下查询:
SELECT * FROM all_data AS a
INNER JOIN
(SELECT * FROM result_dump where email IN
(SELECT `email`
FROM `result_dump`
WHERE `date` = "open"
GROUP BY `email`
HAVING count(email) >3
ORDER BY count(email) DESC)) AS b
ON a.email = b.email
WHERE b.`result` = "open"
另一答案
这很好......试试这个......
SELECT title.title,count(*),title.production_year,title.id as movie_id,title.flag as language,movie_info.info from title INNER JOIN movie_info ON title.id = movie_info.movie_id;
以上是关于内连接+计数+分组依据的主要内容,如果未能解决你的问题,请参考以下文章