此查询将DATETIME转换为DATE,并返回同一DATE的行数。
select*, DATE(call_end) AS Date,
COUNT(*) AS num_emails
from mk_calls mkc
where call_end >= CURDATE() - INTERVAL 10 DAY
GROUP BY DATE(call_end)
ORDER BY call_start
我想知道在知道日期后如何执行类似的查询吗?这可行吗?
$today_date = '2019-06-09';
//perform count query here
答案 0 :(得分:2)
您可以使用MySQLi准备好的语句轻松地做到这一点。
$sql = 'SELECT *, DATE(call_end) AS Date, COUNT(*) AS num_emails
FROM mk_calls mkc
WHERE call_end >= ?
GROUP BY DATE(call_end)
ORDER BY call_start';
$today_date = '2019-06-09';
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('s', $today_date);
$stmt->execute();
使用SELECT *
通常是个坏主意,特别是如果您使用GROUP BY