m0_65749592 2022-10-14 16:22 采纳率: 34.4%
浏览 26
已结题

这两个sql. 下面那两个条件等于号是选择一个玩家就只出现一个

    <select id="getPlayerNotes" parameterClass="java.util.Map" resultClass="PlayerGameRecord">
   select CREATE_TIME as createTime,PLAYER_INDEX as playerIndex,GAME_TYPE_ID as gameTypeId,SURPLUS_GOLD as surplusGold  from $tableName$
   WHERE DATE_FORMAT(CREATE_TIME,'%Y%m%d') = #date#
   <isNotNull property="startTime" prepend="AND">
        <![CDATA[ CREATE_TIME >= #startTime# ]]>
    </isNotNull>
    <isNotNull property="playerIndex" prepend="AND">
        <![CDATA[ PLAYER_INDEX = #playerIndex# ]]>
    </isNotNull>
    <isNotNull property="gameTypeId" prepend="AND">
        <![CDATA[ GAME_TYPE_ID = #gameTypeId# ]]>
    </isNotNull>
    order by create_time ASC LIMIT 1
</select>    
 <select id="getPlayerCoreProtect" parameterClass="java.util.Map" resultClass="PlayerGameRecord">
   select CREATE_TIME as createTime,PLAYER_INDEX as playerIndex,GAME_TYPE_ID as gameTypeId,SURPLUS_GOLD as surplusGold  from $tableName$
   WHERE DATE_FORMAT(CREATE_TIME,'%Y%m%d') = #date#
   <isNotNull property="startTime" prepend="AND">
        <![CDATA[ CREATE_TIME >= #startTime# ]]>
    </isNotNull>
    <isNotNull property="playerIndex" prepend="AND">
        <![CDATA[ PLAYER_INDEX = #playerIndex# ]]>
    </isNotNull>
    <isNotNull property="gameTypeId" prepend="AND">
        <![CDATA[ GAME_TYPE_ID = #gameTypeId# ]]>
    </isNotNull>
    order by create_time desc LIMIT 1
</select> 
  • 写回答

1条回答 默认 最新

  • 一剑荒芜 2022-10-14 16:26
    关注
    <select id="getAll" parameterClass="java.util.Map" resultClass="PlayerGameRecord">
    SELECT * FROM(
        SELECT xx.* FROM 
        (
            SELECT 
            CREATE_TIME, PLAYER_INDEX, SURPLUS_GOLD
            FROM `t_player_game_record__20221011` 
            WHERE DATE_FORMAT(CREATE_TIME,'%Y%m%d') = #date#
                <isNotNull property="startTime" prepend="AND">
                    <![CDATA[ CREATE_TIME >= #startTime# ]]>
                </isNotNull>
                <isNotNull property="playerIndex" prepend="AND">
                    <![CDATA[ PLAYER_INDEX = #playerIndex# ]]>
                </isNotNull>
                <isNotNull property="gameTypeId" prepend="AND">
                    <![CDATA[ GAME_TYPE_ID = #gameTypeId# ]]>
                </isNotNull>
            ORDER BY CREATE_TIME DESC
            LIMIT 99999999
        )xx
        GROUP BY xx.PLAYER_INDEX 
         UNION
        SELECT xx.* FROM 
        (
            SELECT 
            CREATE_TIME, PLAYER_INDEX, SURPLUS_GOLD
            FROM `t_player_game_record__20221011` 
            WHERE DATE_FORMAT(CREATE_TIME,'%Y%m%d') = #date#
                <isNotNull property="startTime" prepend="AND">
                    <![CDATA[ CREATE_TIME >= #startTime# ]]>
                </isNotNull>
                <isNotNull property="playerIndex" prepend="AND">
                    <![CDATA[ PLAYER_INDEX = #playerIndex# ]]>
                </isNotNull>
                <isNotNull property="gameTypeId" prepend="AND">
                    <![CDATA[ GAME_TYPE_ID = #gameTypeId# ]]>
                </isNotNull>
            ORDER BY CREATE_TIME ASC
            LIMIT 99999999
        )xx
         GROUP BY xx.PLAYER_INDEX 
        )yy
    ORDER BY yy.PLAYER_INDEX
    </select> 
    
    <select id="getPlayerNotes" parameterClass="java.util.Map" resultClass="PlayerGameRecord">
    SELECT xx.* FROM 
        (
            SELECT 
            CREATE_TIME, PLAYER_INDEX, SURPLUS_GOLD
            FROM `t_player_game_record__20221011` 
            WHERE DATE_FORMAT(CREATE_TIME,'%Y%m%d') = #date#
                <isNotNull property="startTime" prepend="AND">
                    <![CDATA[ CREATE_TIME >= #startTime# ]]>
                </isNotNull>
                <isNotNull property="playerIndex" prepend="AND">
                    <![CDATA[ PLAYER_INDEX = #playerIndex# ]]>
                </isNotNull>
                <isNotNull property="gameTypeId" prepend="AND">
                    <![CDATA[ GAME_TYPE_ID = #gameTypeId# ]]>
                </isNotNull>
            ORDER BY CREATE_TIME ASC
            LIMIT 99999999
        )xx
        GROUP BY xx.PLAYER_INDEX 
        ORDER BY xx.CREATE_TIME  DESC
    <select>
    
    <select id="getPlayerCoreProtect" parameterClass="java.util.Map" resultClass="PlayerGameRecord">
    SELECT xx.* FROM 
        (
            SELECT 
            CREATE_TIME, PLAYER_INDEX, SURPLUS_GOLD
            FROM `t_player_game_record__20221011` 
            WHERE DATE_FORMAT(CREATE_TIME,'%Y%m%d') = #date#
                <isNotNull property="startTime" prepend="AND">
                    <![CDATA[ CREATE_TIME >= #startTime# ]]>
                </isNotNull>
                <isNotNull property="playerIndex" prepend="AND">
                    <![CDATA[ PLAYER_INDEX = #playerIndex# ]]>
                </isNotNull>
                <isNotNull property="gameTypeId" prepend="AND">
                    <![CDATA[ GAME_TYPE_ID = #gameTypeId# ]]>
                </isNotNull>
            ORDER BY CREATE_TIME DESC
            LIMIT 99999999
        )xx
         GROUP BY xx.PLAYER_INDEX 
         ORDER BY xx.CREATE_TIME  DESC
    <select>
                
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月31日
  • 已采纳回答 10月31日
  • 创建了问题 10月14日