mysql if函数使用例子


1.场景一

有时查询数量a 同时查询过滤后的数量b

 

2. 代码

SELECT
    count(id) as total_count,
    count(
        IF (
            date(order_time) = DATE(now()),
            1,
            NULL
        )
    ) as today_count
FROM
    passenger_activity_record
where a = #{a,jdbcType=INTEGER}
and b_id= #{bId,jdbcType=INTEGER}

3. 说明

3.1 可以嵌套

3.2 ifnull(condition, expr1)功能类似 当condition为null 则返回expr1 ,否则返回 condition

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM