分组取出值最大的数据

1.要去某段时间内的数据,要求每天的数据只取id最大的一条

 

###查询去重取每天的id最大的数据#####
SELECT
    highPressure,
    lowVoltage,
    pulse,
    ADDTIME,
    uid,
    DATE_FORMAT( uploadTime, '%Y-%m-%d' ) AS uploadTime,
    id 
FROM
    bloodpressure 
WHERE
    id IN (
    SELECT
        max( id ) 
    FROM
        bloodpressure 
    WHERE
        highPressure IS NOT NULL 
        AND deleteStatus = 0 
        AND uid = 32854 
        AND DATE_FORMAT( uploadTime, '%Y-%m-%d' ) >= '2017-03-15' 
        AND DATE_FORMAT( uploadTime, '%Y-%m-%d' ) <= '2018-12-06' 
    GROUP BY
        DATE_FORMAT( uploadTime, '%Y-%m-%d' ) 
    )

结果就获得想要的东西:

 

 

posted @ 2019-07-09 18:13  坠落凡尘的魔鬼  阅读(693)  评论(0编辑  收藏  举报