前述
题目描述
leetcode题目:1581. 进店却未进行过交易的顾客
Code
select V.customer_id, count(*) as count_no_trans
from Visits V
left join Transactions T
on V.visit_id = T.visit_id
where transaction_id is null
group by V.customer_id
注意:
=null
返回结果是0行;is null
返回指定的行数。- MySQL 中 null 不代表任务实际的值,类似于一个未知数。
- null 在MySQL中不代表任何值,通过运算符是得不到任何结果的,因此只能用 is null(默认情况)
- 过滤条件得要用
transaction_id is null
,它是该表中具有唯一值的列。不能用amount is null
, 以防下述的测试用例。
错误示例: