mysql 保留一行不变其他行排序

wylc123 1年前 ⋅ 1566 阅读
<select id="GetSnCityDataByYear" parameterType="java.util.Map" resultMap="BaseResultMap">
  	select * from (  
  	(
  		SELECT c.CityID,c.CityName,y.YearDimID,y.YearName,i.IndicatorID,i.IndicatorName,ey.Total,ey.Ranking,ey.GrownPercent,ey.GrownRanking
		FROM indicator i LEFT JOIN economicdatayear ey ON i.IndicatorID = ey.IndicatorID
		LEFT JOIN yeardim y on y.YearDimID = ey.YearDimID
		LEFT JOIN city c ON c.CityID = ey.CityID
		where i.IndicatorStatus = 1 and c.IsShengneiCity = 1 and c.IsCityArea = 0 and c.CityID = 1
		and i.IndicatorID = #{zbId}
		and y.YearDimID = #{year}
  	)
  	union all
  	(
	  	SELECT c.CityID,c.CityName,y.YearDimID,y.YearName,i.IndicatorID,i.IndicatorName,ey.Total,ey.Ranking,ey.GrownPercent,ey.GrownRanking
		FROM indicator i LEFT JOIN economicdatayear ey ON i.IndicatorID = ey.IndicatorID
		LEFT JOIN yeardim y on y.YearDimID = ey.YearDimID
		LEFT JOIN city c ON c.CityID = ey.CityID
		where i.IndicatorStatus = 1 and c.IsShengneiCity = 1 and c.IsCityArea = 0 and c.CityID != 1
		and i.IndicatorID = #{zbId}
		and y.YearDimID = #{year}
	)
	) t 
	order by CityID = 1 desc
	<if test="con==0">
  		,Total desc
  	</if>
	<if test="con==1">
  		,Ranking
  	</if>
  	<if test="con==2">
  		,Ranking desc
  	</if>
  	<if test="con==3">
  		,GrownRanking 
  	</if>
  	<if test="con==4">
  		,GrownRanking desc
  	</if>
  </select>
更多内容请访问:IT源点

相关文章推荐

全部评论: 0

    我有话说: