您的位置:首页 > 数据库 > MySQL

mysql if函数使用例子

2017-11-17 15:21 387 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: