This question already has an answer here:
这个问题在这里已有答案:
- How select for not used codes in this sample 2 answers
如何选择此示例中的未使用代码2答案
The question I'm trying to answer is
我想回答的问题是
Write a SELECT statement that returns the CategoryName column from the Categories table. Return one row for each category that has never been assigned to any product in the Products table. To do that, use a subquery introduced with the NOT EXISTS operator.
编写一个SELECT语句,返回Categories表中的CategoryName列。为从未分配给Products表中任何产品的每个类别返回一行。为此,请使用NOT EXISTS运算符引入的子查询。
The Categories table includes the columns: CategoryID
and CategoryName
Categories表包括列:CategoryID和CategoryName
The Products table includes the columns: ProductID
,CategoryID
,ProductCode
,ProductName
,Description
,ListPrice
,DiscountPercent
,DateAdded
Products表包括以下列:ProductID,CategoryID,ProductCode,ProductName,Description,ListPrice,DiscountPercent,DateAdded
This is what I've tried:
这就是我尝试过的:
SELECT CategoryName
From Categories
Where NOT EXISTS(SELECT CategoryID FROM Products WHERE CategoryID IS NOT NULL)
Anything helps, thanks!
什么都有帮助,谢谢!
1 个解决方案
#1
0
I believe I got it to work with the following code:
我相信我可以使用以下代码:
SELECT CategoryName
From Categories
Where NOT EXISTS(SELECT CategoryID FROM Products)
It returned the desired results and fit the critiria of the question. Thanks anyway guys!
它返回了预期的结果并符合问题的批评。谢谢你们!
#1
0
I believe I got it to work with the following code:
我相信我可以使用以下代码:
SELECT CategoryName
From Categories
Where NOT EXISTS(SELECT CategoryID FROM Products)
It returned the desired results and fit the critiria of the question. Thanks anyway guys!
它返回了预期的结果并符合问题的批评。谢谢你们!