0% found this document useful (0 votes)
2 views2 pages

LeetCode_SQL50_Revision

leet

Uploaded by

placehetvideo1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

LeetCode_SQL50_Revision

leet

Uploaded by

placehetvideo1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Problem 1.

Recyclable and Low Fat Products


Find the ids of products that are both low fat and recyclable.

Input Table(s):
product_id low_fats recyclable
1 Y N
2 Y Y
3 N Y

Expected Output:
product_id
2

SQL Query:
SELECT product_id
FROM Products
WHERE low_fats = 'Y' AND recyclable = 'Y';

Explanation:
We filter rows where both conditions hold true using `WHERE` with `AND`.
Problem 2. Find Customer Referee
Find the names of customers whose referee_id is not equal to 2.

Input Table(s):
id name referee_id
1 Will
2 Jane
3 Alex 2
4 Bill
5 Zack 1
6 Mark 2

Expected Output:
name
Will
Jane
Bill
Zack

SQL Query:
SELECT name
FROM Customer
WHERE referee_id IS NULL OR referee_id != 2;

Explanation:
We must use `IS NULL` instead of `= 'null'`. This query finds customers without a referee or with a
referee different from 2.

You might also like