当前位置:网站首页>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 ?
边栏推荐
- [advanced pointer I] character array & array pointer & pointer array
- Domain name mapping to specified IP
- Regular verification user name
- Wechat applet image saving function
- 2024. maximum difficulty of the exam - sliding window
- Background fixing effect
- Sword finger offer:[day 8 dynamic planning (simple)] --- > frog jumping on steps
- Background location case II
- torch. logical_ And() method
- Dynamically create and submit forms
猜你喜欢

xshell启动遇到“由于找不到mfc110.dll,无法继续执行代码的解决方法”

Notes used by mqtt (combined with source code)

Display the remaining valid days according to the valid period

【字符集八】char8_t、char16_t、char32_t、wchar、char

Background location case 1

Does database and table splitting cause reading diffusion problems? How to solve it?

Flink CheckPoint : Exceeded checkpoint tolerable failure threshold
![(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit](/img/c1/d56ec09663857afa52f20848aeadac.png)
(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit

Flink passes in custom parameters or profiles

域名映射到指定IP
随机推荐
Background position - mixed units
(js)三位用逗号隔开,保留两位小数(or 四舍五入取整)
Flink passes in custom parameters or profiles
Analysis of 43 cases of MATLAB neural network: Chapter 8 prediction of GRNN Network - Freight Volume Prediction Based on generalized regression neural network
Union selector
UMI packaging and subcontracting, and compressing to gzip
JS to refresh the page after loading
[sklearn] lightgbm
Flink传入自定义的参数或配置文件
Get last month, current time and next month
2022.6.11-----leetcode. nine hundred and twenty-six
2022 melting welding and thermal cutting test questions and answers
Handling abnormal data
torch. logical_ And() method
最少换乘次数
About weights exercise
Composition of box model
Introduction to Chang'an chain node certificate, role and authority management
Make a simple page with the websql database of HTML5:
MySQL - Import / export operation