【SQL】1581. 进店却未进行过交易的顾客( is null 和 =null 的区别)

前述

MySQL 中 is null 和 =null 的区别

题目描述

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

注意:

  1. =null 返回结果是0行; is null 返回指定的行数。
    • MySQL 中 null 不代表任务实际的值,类似于一个未知数。
    • null 在MySQL中不代表任何值,通过运算符是得不到任何结果的,因此只能用 is null(默认情况)
  2. 过滤条件得要用 transaction_id is null,它是该表中具有唯一值的列。不能用amount is null, 以防下述的测试用例。
    错误示例:
    在这里插入图片描述

相关推荐

  1. SQL--IFNULL()、NULLIF()、ISNULL()函数 简单明了讲解

    2024-03-27 13:54:01       49 阅读
  2. Oracle中Null‘‘区别

    2024-03-27 13:54:01       66 阅读
  3. js nullundefined区别

    2024-03-27 13:54:01       42 阅读
  4. mysql null空值区别

    2024-03-27 13:54:01       42 阅读
  5. QStringisNull与isEmpty

    2024-03-27 13:54:01       55 阅读
  6. Objective-C中nilnull区别

    2024-03-27 13:54:01       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 13:54:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 13:54:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 13:54:01       87 阅读
  4. Python语言-面向对象

    2024-03-27 13:54:01       96 阅读

热门阅读

  1. c# 设置图片透明度

    2024-03-27 13:54:01       41 阅读
  2. 【LAMMPS学习】五、LAMMPS命令(1) LAMMPS 输入脚本

    2024-03-27 13:54:01       38 阅读
  3. 数据库(四)

    2024-03-27 13:54:01       37 阅读
  4. Spring和Spring Boot的区别

    2024-03-27 13:54:01       43 阅读
  5. Mysql数据库:索引

    2024-03-27 13:54:01       42 阅读
  6. C++服务内存分析

    2024-03-27 13:54:01       39 阅读
  7. STEVE - Voracious Steve dfs , 以及为什么不能博弈

    2024-03-27 13:54:01       44 阅读
  8. nginx负载均衡模式

    2024-03-27 13:54:01       41 阅读