要查询某个时间段的数据,查询结果中出现重复的时间
select to_char(timeRecord,'yyyy-MM-dd HH:mm') timeRecord,phValue from
HZBS_PZYS2."pzys_watermonitor" where
timeRecord >= '2021-11-17'
and
waterPlantName = (
select waterPlantName from
HZBS_PZYS2."pzys_watermonitor" where id='cecef4f8-3bfe-4641-a7be-4f97b748f979'
)
如果每个时间段的phValue相同,可以使用DISTINCT函数去重,这里因为值不相同,使用DISTINCT函数去重会失败,可以使用group by + min来去重
select to_char(timeRecord,'yyyy-MM-dd HH:mm') timeRecord,MIN(phValue) phValue from
HZBS_PZYS2."pzys_watermonitor" where
timeRecord >= '2021-11-17'
and
waterPlantName = (
select waterPlantName from
HZBS_PZYS2."pzys_watermonitor" where id='cecef4f8-3bfe-4641-a7be-4f97b748f979'
)
group by to_char(timeRecord,'yyyy-MM-dd HH:mm')
可以看到已经成功去重时间重复的数据