对于 PostgreSQL,你可以参考以下 SQL 查询获取本周的数据:
SELECT
extract(epoch from clock) as timestamp,
itemid,
value
FROM
history
WHERE
clock >= date_trunc('week', current_date)
AND clock < date_trunc('week', current_date) + interval '1 week'
ORDER BY
itemid, clock;
对于 MySQL,你可以参考以下 SQL 查询:
SELECT
UNIX_TIMESTAMP(clock) as timestamp,
itemid,
value
FROM
history
WHERE
clock >= date_sub(curdate(), interval weekday(curdate()) day)
AND clock < date_add(date_sub(curdate(), interval weekday(curdate()) day), interval 1 week)
ORDER BY
itemid, clock;