我有一张包含IP会计数据的表,
我希望每个月(jan,feb,mar ...)获得SUM(bytes)
,从当天开始,为期一年
column: bytes <-- bytes
column: timeanddate <-- timestamp
我的查询:
SELECT (SELECT SUM(bytes) FROM ip_accounting);
请帮忙。
答案 0 :(得分:0)
我已经找到了想要的答案
SELECT
SUM(download_bytes) as download_bytes,
SUM(upload_bytes) as upload_bytes,
SUM(download_bytes + upload_bytes) as total_bytes,
DAY(date) as day,
MONTHNAME(date) as month
FROM
traffic_counters
LEFT JOIN services ON traffic_counters.service_id = services.id
WHERE
date >= (NOW() - INTERVAL 1 MONTH)
GROUP BY
MONTH(date),
DAY(date)
ORDER BY
MONTH(date),
DAY(date)