当前位置:网站首页>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 ?
边栏推荐
- [character set 7] what are the wide character codes and multi byte codes of Chinese characters
- Flink CheckPoint : Exceeded checkpoint tolerable failure threshold
- Load the source code of 2D 3D virtual anchor in the web page (1: project introduction and source code)
- (node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit
- (十二)交互组件Selectable
- Chapter 3 registers (memory access)
- The difference between deep copy and shallow copy
- 【字符集九】gbk拷贝到Unicode会乱码?
- 目标识别、检测和 6D 姿态估算源码与方案(最先进的方法和数据集)
- node示例后台搭建
猜你喜欢

MFS explanation (IV) -- MFS management server installation and configuration

Chapter 3 registers (memory access)

清华大学数据挖掘笔记(一)

Flink CheckPoint : Exceeded checkpoint tolerable failure threshold

Set up redis sentinel cluster (instance):

第八章-数据处理的两个基本问题

分库分表会带来读扩散问题?怎么解决?

Composition of box model

2022 safety officer-c certificate special operation certificate examination question bank and simulation examination

Redis installation test
随机推荐
Difference between binary GB and gib
动态线段树leetcode.699
Judge whether the object is empty
Chapter 7 - more flexible location of memory addresses
128. Plus longue séquence continue - table de hachage
第四章-第一个程序
Can you migrate backwards before the first migration in the south- Can you migrate backwards to before the first migration in South?
域名映射到指定IP
(十二)交互组件Selectable
The difference between deep copy and shallow copy
The database doesn't know what went wrong
UMI packaging and subcontracting, and compressing to gzip
Dynamically create and submit forms
QT realizes multi screen and multi-resolution adaptation
Union selector
2022 simulated examination platform operation of high voltage electrician work license question bank
第八章-数据处理的两个基本问题
[character set 8] char8_ t、char16_ t、char32_ t、wchar、char
2022.6.11-----leetcode. nine hundred and twenty-six
Chapter VI - procedures with multiple segments