SELECT *, @rownum := @rownum + 1 AS tmp, @incrnum := CASE WHEN @rowtotal = ${field} THEN @incrnum WHEN @rowtotal := ${field} THEN @rownum END AS rownum FROM (SELECT * from (SELECT * from aqi_hour_site WHERE 1=1 <if test="cityCode != null and cityCode != ''"> AND city_code = #{cityCode} </if> <if test="arrayList!=null and arrayList.size()>0"> AND site_code in <foreach collection="arrayList" item="item" index="index" open="(" separator="," close=")">#{item}</foreach> </if> ORDER BY data_time desc LIMIT 2000) d GROUP BY site_code <if test="dataSort==1">ORDER BY ${field} asc</if> <if test="dataSort==2">ORDER BY ${field} desc</if> ) as a, (SELECT @rownum := 0, @rowtotal := NULL, @incrnum := 0) b
时间: 2024-02-15 12:27:01 浏览: 142
C# Mysql 查询 Rownum的解决方法
这段代码看起来像是一个SQL查询语句,其中包含了一些参数以及条件筛选。具体来说,它查询了一个叫做aqi_hour_site的表,并根据一些条件进行筛选,比如cityCode和site_code。查询结果按照data_time进行降序排列,并且只取前2000条数据。然后,再对结果按照site_code进行分组,并且使用MySQL的变量来计算每个分组的行号,以便于后续的排序。最后,根据参数dataSort的值,对结果进行升序或降序排序。
阅读全文