<?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="utility">

<!-- For Maria DB -->
<sql id="paging-prefix"><if test="fetchSize != null and fetchSize &gt; 0">
SELECT QROWS.* FROM (       
  SELECT ROW_NUMBER() OVER(<include refid="utility.sortBy" />) ROW_NUM
       , COUNT(*) OVER() TOT_CNT, QBODY.*
    FROM (</if></sql>

<sql id="paging-suffix"><if test="fetchSize != null and fetchSize &gt; 0">       ) QBODY
  ) QROWS
WHERE ROW_NUM BETWEEN ((#{pageNum} - 1) * #{fetchSize}) + 1 AND (#{pageNum} * #{fetchSize})</if></sql>

<select id="foundRows" resultType="dataobject">/* 전체 결과수 가져오기(utility.foundRows) */
SELECT FOUND_ROWS() TOT_CNT</select>

<sql id="sortBy"><if test="orderBy != null and orderBy != ''">ORDER BY ${orderBy}</if></sql>

<sql id="orderBy"><if test="fetchSize == null or fetchSize &lt; 1"><include refid="utility.sortBy" /></if></sql>

<sql id="now">DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y%m%d%H%i%s')</sql>

<sql id="selectNow">SELECT<include refid="utility.now" />NOW</sql>

<sql id="today">DATE_FORMAT(CURRENT_DATE, '%Y%m%d')</sql>

<sql id="selectToday">SELECT<include refid="utility.today" />TODAY</sql>

<sql id="thisDay">IFNULL(#{thisDay},<include refid="utility.today" />)</sql>

<sql id="selectThisDay">SELECT<include refid="utility.thisDay" />THIS_DAY</sql>

</mapper>