mySQL:定期分组

时间:2018-08-14 18:30:42

标签: mysql

我有一张桌子,上面有所有10分钟的价格和时间戳。我想每天获取过去5天的最低价格。我想我需要自我连接表,但是如何形成ON子句和GROUP子句?

2 个答案:

答案 0 :(得分:0)

可能的查询:

SELECT DAY(timestampCol), MIN(price)
FROM table
GROUP BY DAY(timestampCol)
LIMIT 5;

答案 1 :(得分:0)

SELECT
    MIN(Price) AS minPrice,
    DATE(ColTimestamp) AS thatDay,
    someProduct
FROM yourTable
WHERE DATE(ColTimestamp) > (SUBDATE(CURDATE(),INTERVAL 5 DAY)
GROUP BY someProduct,
         DATE(ColTimestamp);