简体   繁体   中英

MYSQL get record from last week weekday

I have a table contains temperature record of a machine every second as below. And I want to get the minimum and max value of each column (CH1~CH20) from last week's weekday. Is it possible to do it? I'm now stuck on how to select record from last week weekday.Thanks for any help!~

我的桌子

SELECT MAX(CH1) FROM table where date < '2017-07-15' AND date > 2017-07-16';

For minimum use MIN instead of MAX. This could help you for each columns step by step.

Something like this ?

SELECT MIN(CH1), MAX(CH1), MIN(CH2), MAX(CH2) FROM TABLE 
WHERE 
Date >= DATE_SUB(CURDATE(), INTERVAL 7 + WEEKDAY(CURDATE()) DAY) 
AND
Date < DATE_SUB(CURDATE(), INTERVAL 2 + WEEKDAY(CURDATE()) DAY);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM