我在表customer_class_bookings中根据其他表trader_job_payment的IF条件找到了total的总和。我的问题是,它给的是0,这是错误的。以下是我的代码
select SUM(IF (trader_job_payment.status = 'DISBURSED' , customer_class_bookings.total, 0))
AS earning from `customer_class_bookings`
left join `trader_job_payment` on `trader_job_payment`.`payable_id` = `customer_class_bookings`.`id` and
`trader_job_payment`.`payable_type` = 'Modules\\WellBeing\\Models\\CustomerClassBooking' and `trader_job_payment`.`deleted_at` = null where `trader_user_id` = 917earning是0,这是错误的。有没有人能帮我解决这个问题。谢谢
发布于 2020-01-17 22:29:20
您正在检查值" NULL“,而不是检查单元格是否为NULL。Null不是MySql中的值。您必须使用IS NULL函数,如下所示:
SELECT *
FROM contacts
WHERE last_name IS NULL;因此,您的查询将变为(仅限修改部分):
`trader_job_payment`.`deleted_at` IS NULL您可以了解有关如何处理空here的更多信息。
https://stackoverflow.com/questions/59789305
复制相似问题