mybatis 动态行转列

mybatis 动态行转列mybatis 动态行转列

SELECT user_name ,
MAX(CASE course WHEN '数学' THEN score END ) 数学,
MAX(CASE course WHEN '语文' THEN score END ) 语文,
MAX(CASE course WHEN '英语' THEN score END ) 英语
FROM test_tb_grade
GROUP BY USER_NAME;

在 mybatis 中实现 动态行转列

<select id="list" resultType="java.util.HashMap">
  SELECT user_name ,
    <if test="courses != null">
    <foreach collection="courses " item="item" separator=",">
        MAX(CASE course WHEN #{item} THEN score END ) "${item}"
    </foreach>
    </if>
  FROM test_tb_grade
  GROUP BY USER_NAME;
</select>
上一篇:WP 类似扑克牌布局控件和类似扑克卡片控件


下一篇:SUN巡检命令