sql语句出现group by分组之后查询其他非分组字段的方式

如题,当sql中出现group by时这时其他非分组字段只能带函数才能出现在select列中,所以最好的办法只能连表去查询其他字段

 

    @Select("<script>" +
            "select A.* from sc_potable_water_sources_monitor_hour A INNER JOIN ( SELECT C.station_name AS stationName, max(C.data_time) AS dataTime " +
            "FROM sc_potable_water_sources_monitor_hour C where C.station_name in " +
            "<foreach item='item' index='index' collection='stationNameList' open='(' separator=',' close=')'> #{item} </foreach>"+
            "GROUP BY C.station_name ) r ON A.station_name = r.stationName " +
            "AND A.data_time = r.dataTime " +
            "</script>")
    List<ScPotableWaterSourcesMonitorHourDO> selectAppMapData(@Param("stationNameList") Collection<String> stationNameList);

 

posted @ 2022-12-23 10:45  云翊宸  阅读(272)  评论(0)    收藏  举报