码迷,mamicode.com
首页 > 数据库 > 详细

MySQL与mabits大小比较、日期比较示例

时间:2016-06-06 17:00:47      阅读:1692      评论:0      收藏:0      [点我收藏+]

标签:

首先,使用mysql查询从今往后的60天数据

SELECT
	count(*),
	b1.record_date
FROM
	nk_house_use_record AS b1,
	(
		SELECT
			a.theme_id,
			a.theme_name,
			b.house_id,
			b.house_name
		FROM
			nk_house_theme AS a,
			nk_house AS b
		WHERE
			a.theme_id = ‘08a649fd-b83e-41b5-b88b-99598d4c93fe‘
		AND a.theme_id = b.theme_id
		AND a.state = ‘1‘
		AND b.state = ‘1‘
	) AS a1
WHERE
	a1.house_id = b1.house_id
AND time1 = ‘0‘
AND record_date >= CURDATE() #‘2016-06-05‘ 
AND record_date < DATE_SUB(CURDATE(), INTERVAL - 60 DAY)
GROUP BY
	b1.record_date

其次,移植到mabits中

<select id="queryFreeHouseCalender" resultType="com.cn.front.entity.detail.FreeHouseCalender" parameterType="com.cn.front.entity.input.QueryFreeHouse">
        SELECT
            count(*) AS num,
            b1.record_date
        FROM
            nk_house_use_record AS b1,
            (
                SELECT
                    a.theme_id,
                    a.theme_name,
                    b.house_id,
                    b.house_name
                FROM
                    nk_house_theme AS a,
                    nk_house AS b
                WHERE
                    a.theme_id = #{themeID}
                AND a.theme_id = b.theme_id
                AND a.state = ‘1‘
                AND b.state = ‘1‘
            ) AS a1
        WHERE
            a1.house_id = b1.house_id            
        <if test="timeKey == ‘1‘ ">and time1 = ‘0‘</if>                
        <if test="timeKey == ‘2‘ ">and time2 = ‘0‘</if>                
        <if test="timeKey == ‘3‘ ">and time3 = ‘0‘</if>                
        <if test="timeKey == ‘4‘ ">and time4 = ‘0‘ and time5=‘0‘</if>    
        
        <if test="startDate != null">AND record_date &gt;=  #{startDate}</if>    
        <if test="endDate != null">AND record_date &lt;= #{endDate}</if>    
        
        <if test="startDate == null">AND Date(record_date) &gt;= CURDATE() </if>    
        <if test="endDate == null">AND Date(record_date) &lt; DATE_SUB(CURDATE(), INTERVAL - 60 DAY) </if>            
        GROUP BY
            b1.record_date
    </select>

 

xml特殊符号转义写法

&lt; <

&gt; >

&lt;&gt; <>

&amp; &

&apos; ‘

&quot; "

 

MySQL与mabits大小比较、日期比较示例

标签:

原文地址:http://www.cnblogs.com/jianfeijiang/p/5563581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!