The following basic-level SQL problems.
LeetCode 610
Triangle Judgement (Easy) [link]
Using CASE WHEN
SELECT x, y, z,
CASE
WHEN x + y > z AND x + z > y AND y + z > x THEN 'Yes'
ELSE 'No'
END AS triangle
FROM Triangle;
Using IF
SELECT x, y, z,
IF(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle
FROM Triangle;
LeetCode 614
Second Degree Follower (Medium) [link]
SELECT followee AS follower, COUNT(followee) AS num
FROM Follow
WHERE followee IN (
SELECT follower
FROM Follow
)
GROUP BY followee
ORDER BY followee;
LeetCode 1068
Product Sales Analysis I (Easy) [link]
SELECT p.product_name, s.year, s.price
FROM Sales s
LEFT JOIN Product p
ON s.product_id = p.product_id;
LeetCode 1069
Product Sales Analysis II (Easy) [link]
SELECT s.product_id, SUM(s.quantity) AS total_quantity
FROM Sales s
LEFT JOIN Product p
ON s.product_id = p.product_id
GROUP BY s.product_id;