SELECT DATE_FORMAT(AddTime, "%Y-%m-%d") DAY, min(count) min, addtime mintime, max(count) max, addtime maxtime FROM allonlinecount GROUP BY DAY;
count
addtime 是添加记录的时间,本人查询出来,都第一条记录的时间,要怎样才能查询到min以及max值的记录时间,min跟max的值有重复的可能
解决方案
40
SELECT
DATE_FORMAT(AddTime, “%Y-%m-%d”) DAY,
min(count) min,
(select AddTime from allonlinecount where DATE_FORMAT(AddTime, “%Y-%m%-%d”)=DATE_FORMAT(AddTime, “%Y-%m-%d”) order by `count` desc limit 1) as mintime ,
max(count) max,
(select AddTime from allonlinecount where DATE_FORMAT(AddTime, “%Y-%m%-%d”)=DATE_FORMAT(AddTime, “%Y-%m-%d”) order by `count` asc limit 1) as maxtime
FROM
allonlinecount
GROUP BY
DAY;
DATE_FORMAT(AddTime, “%Y-%m-%d”) DAY,
min(count) min,
(select AddTime from allonlinecount where DATE_FORMAT(AddTime, “%Y-%m%-%d”)=DATE_FORMAT(AddTime, “%Y-%m-%d”) order by `count` desc limit 1) as mintime ,
max(count) max,
(select AddTime from allonlinecount where DATE_FORMAT(AddTime, “%Y-%m%-%d”)=DATE_FORMAT(AddTime, “%Y-%m-%d”) order by `count` asc limit 1) as maxtime
FROM
allonlinecount
GROUP BY
DAY;