条件返回参数

本文介绍了一种在SQL查询中处理字段可能为空值的情况的方法,通过使用CASE WHEN和IFNULL函数,可以有效地将null值转换为特定的状态码,确保数据的一致性和准确性。这种方法在复杂的数据处理场景中尤其有用。
背景

返回的参数按照条件 如果字段为null值 则 返回0 状态,不为null则返回 1状态

思路

使用if实现SQL语句中的判断

解决方案
		select  ac.tuid,ac.limit_price,ac.task_name,dt.task_goal,dt.task_type,dg.good_num,dg.product_code,dg.good_type,(case when rt.entity_id is null then 0 else 2 end ) status,
		IFNULL(finish_num,0) finish_num,IFNULL(is_finish,0)  is_finish,IFNULL(is_receive,0)  is_receive,s.product_code chest_code
		from pm_activity_relation ac
		inner join pm_dotask dt on ac.task_id=dt.dotask_id 
		inner join 
		(select dg.task_id,GROUP_CONCAT(s.product_code) product_code,GROUP_CONCAT(dg.good_num) good_num,GROUP_CONCAT(dg.good_type) good_type
		 from pm_dotask_goods dg inner join pm_shop s on dg.good_id=s.tuid group by dg.task_id)
		dg on dt.dotask_id=dg.task_id
		left join (select  entity_id,finish_num,is_finish,is_receive  from pm_role_finish_task where entity_type=#{entityType} and role_id=#{roleId} )  rt on ac.tuid=rt.entity_id
		left join  pm_shop s on ac.chest_id=s.tuid 
		where ac.activity_id=#{activityId}
解决问题

还有其他方法.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值