当前位置:网站首页>Exists usage in SQL
Exists usage in SQL
2022-06-12 09:00:00 【CSDN Q & A】
There are products Product And sales records Sales Two tables
Product :
| product_id | product_name | unit_price |
| 1 | S8 | 1000 |
| 2 | G4 | 800 |
| 3 | iPhone | 1400 |
Sales :
| seller_id | product_id | buyer_id | sale_date | quantity | price |
| 1 | 1 | 1 | 2019-01-21 | 2 | 2000 |
| 1 | 2 | 2 | 2019-02-17 | 1 | 800 |
| 2 | 1 | 3 | 2019-06-02 | 1 | 800 |
| 3 | 3 | 3 | 2019-05-13 | 2 | 2800 |
problem
I bought S8 But I didn't buy iPhone Of buyer_id
Code
select s.buyer_id,
p.product_name
from Product p,
Sales s
where s.product_id =p.product_id
and p.product_name ='S8'
and not exists(select s.buyer_id,
p.product_name
from Product p,
Sales s
where s.product_id =p.product_id and p.product_name ='iPhone')
Wrong results and problems
The result output is empty , I'll buy it first S8 Customers , And I haven't bought iPhone, Here we use not exists Why didn't it work ?
边栏推荐
- Source code and scheme for target recognition, detection and 6D attitude estimation (the most advanced method and data set)
- 2022.6.9-----leetcode. four hundred and ninety-seven
- Priority issues
- 2022 safety officer-c certificate special operation certificate examination question bank and simulation examination
- [character set 8] char8_ t、char16_ t、char32_ t、wchar、char
- 2022 simulated examination platform operation of high voltage electrician work license question bank
- Knee joint
- Handling abnormal data
- 第三章 寄存器 (内存访问)
- 【字符集七】汉字的宽字符码和多字节码分别是多少
猜你喜欢

《MATLAB 神经网络43个案例分析》:第7章 RBF网络的回归--非线性函数回归的实现

Use NVM to dynamically adjust the nodejs version to solve the problem that the project cannot be run and packaged because the node version is too high or too low

【字符集七】汉字的宽字符码和多字节码分别是多少
![[advanced pointer 2] array parameter transfer & pointer parameter transfer & function pointer & function pointer array & callback function](/img/90/447d601a8c338cdd5a6674a2dc59ae.png)
[advanced pointer 2] array parameter transfer & pointer parameter transfer & function pointer & function pointer array & callback function

MFS详解(四)——MFS管理服务器安装与配置

2022 melting welding and thermal cutting test questions and answers

Display the remaining valid days according to the valid period

Priority issues

Building a cluster: and replacing with error

Chapter 8 - two basic problems of data processing
随机推荐
Does database and table splitting cause reading diffusion problems? How to solve it?
MySQL learning records -- III. MySQL query statements
Notes used by mqtt (combined with source code)
【sklearn学习】LightGBM
网页中加载二次元3D虚拟主播源码(1:项目介绍和源码)
IP, DNS, domain name, URL, hosts
长安链节点证书、角色、权限管理介绍
Knee joint
(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit
Flink CheckPoint : Exceeded checkpoint tolerable failure threshold
consul 配置相关
[character set 8] char8_ t、char16_ t、char32_ t、wchar、char
mySql学习记录——二、mySql建表命令
2024. maximum difficulty of the exam - sliding window
2022.6.9-----leetcode. four hundred and ninety-seven
【字符集六】宽字符串和多字节字符互转
Building a cluster: and replacing with error
torch. logical_ And() method
Chapter 8 - two basic problems of data processing
Sword finger offer II 016 Longest substring without repeating characters - sliding window