<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.dbnt.kcgfilemanager.mapper.BoardMapper">
  <select id="selectContentList" resultType="Board" parameterType="Board">
    SELECT A.TITLE AS title,
           C.FILE_CNT AS fileCnt,
           B.NAME AS createName,
           A.CREATE_DATE AS createDate
    FROM BOARD A
      INNER JOIN USER_INFO B
        ON A.CREATE_ID = B.USER_ID
      INNER JOIN (SELECT CONTENT_SEQ, MAX(FILE_SEQ) AS FILE_CNT
                  FROM FILE_INFO
                  GROUP BY CONTENT_SEQ ) C
        ON A.CONTENT_SEQ = C.CONTENT_SEQ
    WHERE A.CATEGORY_SEQ = #{categorySeq}
    ORDER BY A.CREATE_DATE DESC
    LIMIT #{viewCnt} OFFSET #{firstIndex}
  </select>
  <!--<if test="endDate != null and endDate != ''">
    AND A.CREATE_DATE &lt;= #{endDate}
  </if>-->
  <select id="selectContentListCnt" resultType="int" parameterType="int">
    SELECT COUNT(*)
    FROM BOARD A
       INNER JOIN USER_INFO B
          ON A.CREATE_ID = B.USER_ID
       INNER JOIN (SELECT CONTENT_SEQ, MAX(FILE_SEQ) AS FILE_CNT
                   FROM FILE_INFO
                   GROUP BY CONTENT_SEQ ) C
          ON A.CONTENT_SEQ = C.CONTENT_SEQ
    WHERE CATEGORY_SEQ = ${categorySeq}
  </select>
</mapper>