我选择一个开始和结束日期,之后,我想总结所有订单。
如果我们看看我的图像,总和值将是80.从2017-09-02到2017-09-10,共有80个订单。
我想用php回显这个和值。
我的sql代码:
$sql = "
SELECT datum, COUNT(rendeles_id) AS ennyi FROM rendeles_adatok
WHERE datum >= '$date_start' AND (datum <= '$date_end' AND status = $rendeles_allapot)
GROUP BY datum ORDER BY $kereses_sorrend
";
“ennyi”别名是我在当天的订单栏中回显。 (照片上的最后一栏)
答案 0 :(得分:1)
如果您只想要总计,请删除GROUP BY
:
SELECT COUNT(rendeles_id) AS ennyi
FROM rendeles_adatok
WHERE datum >= '$date_start' AND
datum <= '$date_end' AND
status = $rendeles_allapot;
如果除了其他数据外还需要总行数,请使用WITH ROLLUP
:
SELECT datum, COUNT(rendeles_id) AS ennyi
FROM rendeles_adatok
WHERE datum >= '$date_start' AND
datum <= '$date_end' AND
status = $rendeles_allapot
GROUP BY datum WITH ROLLUP;