当前位置:网站首页>sql中的Exists用法
sql中的Exists用法
2022-06-12 08:53:00 【CSDN问答】
有产品Product和销售记录Sales两张表
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 |
问题
查找买了S8但没买iPhone的buyer_id
代码
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')
错误结果和问题
结果输出为空,我先筛选买了S8的顾客,并且没有买过iPhone,这里用not exists为什么没有生效?
边栏推荐
- What is the quality traceability function of MES system pursuing?
- 通俗理解时域采样与频域延拓
- svg中viewbox图解分析
- Random acquisition of 4-digit non repeated verification code
- 2022.6.9-----leetcode. four hundred and ninety-seven
- ERROR 1630 (42000): FUNCTION a.avg does not exist. Check the ‘Function Name Parsing and Resolution‘
- 判断对象是否为空
- Webrtc series - mobile terminal hardware coding supports simulcast
- Audio and video related links
- Hypergeometric cumulative distribution test overlap
猜你喜欢

《MATLAB 神經網絡43個案例分析》:第7章 RBF網絡的回歸--非線性函數回歸的實現

Handling abnormal data
![[advanced pointer III] implement C language quick sorting function qsort & callback function](/img/f0/3729db83ba3eb15c7df0958858ece9.png)
[advanced pointer III] implement C language quick sorting function qsort & callback function

Adjust SVG width and height
![[advanced pointer I] character array & array pointer & pointer array](/img/ea/150b2162e4e1641eee7e852935d101.png)
[advanced pointer I] character array & array pointer & pointer array

JVM learning notes: three local method interfaces and execution engines

Priority issues

Where does the driving force of MES system come from? What problems should be paid attention to in model selection?

What exactly is APS? You will know after reading the article

Set up redis sentinel cluster (instance):
随机推荐
2022 safety officer-c certificate special operation certificate examination question bank and simulation examination
You have an error in your SQL syntax; use near ‘and title=‘xxx‘‘ at line 5
Error: what if the folder cannot be deleted when it is opened in another program
Py & go programming skills: logic control to avoid if else
第五章-[bx]和Loop指令
Principle and configuration of MPLS
(p15-p16) optimization of the right angle bracket of the template and the default template parameters of the function template
Notes used by mqtt (combined with source code)
【sklearn学习】LightGBM
Error: clear the history in the search box in the website?
【指針進階三】實現C語言快排函數qsort&回調函數
Regular verification user name
《MATLAB 神经网络43个案例分析》:第8章 GRNN网络的预测----基于广义回归神经网络的货运量预测
The newline character with in the string is converted to an array
Code generation tool Autocode for XML Publishing
【字符集九】gbk拷贝到Unicode会乱码?
ip、DNS、域名、URL、hosts
2022.6.9-----leetcode. four hundred and ninety-seven
Shell基本语法--数组
正则校验用户名