我只需要在数据库中只返回重复的行30次。我在SELECT之后添加了这个COUNT函数,但老实说不知道下一步要做什么。有人可以建议我吗?
$variable = "SELECT COUNT(mail.h_datetime, sent.f_mail_subject, sent.f_mail_content)"
."FROM mail"
."INNER JOIN sent ON mail.h_id = sent.e_mail_templates_id"
."WHERE f_template_type = 'newsletter'";
答案 0 :(得分:2)
执行GROUP BY
所有选定的行。使用HAVING
仅返回至少出现30次的行。
SELECT mail.h_datetime, sent.f_mail_subject, sent.f_mail_content
FROM mail
INNER JOIN sent ON mail.h_id = sent.e_mail_templates_id
WHERE f_template_type = 'newsletter'
GROUP BY mail.h_datetime, sent.f_mail_subject, sent.f_mail_content
HAVING COUNT(*) >= 30