SQL - Leetcode-01
SQL Schema
Question 1
Write a query to find the ids of products that are both low fat and recyclable.
Question 2
Write a query to get the percentage of certain products:
SQL Schema
Question 3
Write a query to report the names of the customer that are not referred by the customer with id = 2.
The trick here is to handle the NULL cases.
Using COALESCE
COALESCE takes in multiple arguments and returns the first non-null value in the list then check if it is equal to 2
Using ISNULL
SQL Schema
Question 4
Write a query to report all customers who never order anything. Return result in any order.
Basically we need to perform a LEFT JOIN and then find out those with Orders id that IS NULL.
Output showing all customer with their orderId:
So we basically need to adjust the query to select only those with null.
Output showing all customer with NULL orderId: