我在MySQL中有以下存储过程:
SELECT *
FROM rewards
LEFT JOIN tasks
ON tasks.id = rewards.task_id
AND rewards.received_at = received_Date
WHERE tasks.kid_id = kid_Id
ORDER BY tasks.id ASC;
该存储过程有2个(IN)输入: kid_Id
(整数) 和 received_Date
(日期),目前它的运行良好。
问题: 我想要的是,如果received_Date
为NULL
,那么我希望能查看所有日期,这是否可能?
换句话说:
只有在传递received_Date
时,AND rewards.received_at = received_Date
才会起作用,否则将返回所有日期。