我无法计算/分组内部联接的结果
我有两张桌子
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"
答案 0 :(得分:4)
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
我认为这个没有错。
答案 1 :(得分:1)
尝试以下查询:
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"
答案 2 :(得分:-1)
这很好...... 尝试这个..
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;