我需要统计一个月内发送的电子邮件,以及最后发送给每个人的电子邮件。我想象这样的事情:
$mes=8; // or any month
$search= [100,101,102,103]; // dni
$sql = "
SELECT A.dni, $mes AS mes, COUNT(*) AS total, B.lastet_date
FROM emails AS A
LEFT JOIN (
SELECT dni, MAX(date_sended) AS lastet_date
FROM emails
GROUP BY dni
) AS B
ON B.dni = A.dni
WHERE MONTH(date_sended) = $mes
AND A.dni IN ('".implode("', '",$search)."')
GROUP BY A.dni";
我怎样才能简单地使用原始方法或类似方法来执行它?