SQL NULL賦值0 時間區間 查詢運算

<select id="programGetIntegral" parameterType="java.util.Map" resultMap="BaseResultMap">
    SELECT user_id,
    ((select IFNULL(SUM(integral_value),0)
    from integral WHERE type LIKE 0 and user_id LIKE #{userId}
    and create_time &gt; #{dateStart} and create_time &lt; #{dateEnd})
    -
    (select IFNULL(SUM(integral_value),0)
    from integral WHERE type LIKE 1 and user_id LIKE #{userId}
    and create_time &gt; #{dateStart} and create_time &lt; #{dateEnd})) as 'integral_value'
    from integral WHERE user_id LIKE #{userId} group by user_id

</select>

1:NULL賦值0  java

IFNULL(SUM(integral_value),0)

2:時間區間date

and create_time &gt; #{dateStart} and create_time &lt; #{dateEnd}

3:查詢運算select

((select IFNULL(SUM(integral_value),0)
from integral WHERE type LIKE 0 and user_id LIKE #{userId}
and create_time &gt; #{dateStart} and create_time &lt; #{dateEnd})
-
(select IFNULL(SUM(integral_value),0)
from integral WHERE type LIKE 1 and user_id LIKE #{userId}
and create_time &gt; #{dateStart} and create_time &lt; #{dateEnd}))
相關文章
相關標籤/搜索