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}))
相关文章
相关标签/搜索