SELECT sp.name AS'name' FROM SalesPerson sp WHERE sp.sales_id NOTIN ( SELECT o.sales_id FROM Orders o WHERE o.com_id IN ( SELECT c.com_id FROM Company c WHERE c.name ='RED' ) );
SELECT employee_id FROM Employees WHERE employee_id NOTIN ( SELECT employee_id FROM Salaries ) UNION SELECT employee_id FROM Salaries WHERE employee_id NOTIN ( SELECT employee_id FROM Employees ) ORDERBY employee_id;
DELETEFROM Person WHERE id NOTIN (SELECT*FROM( SELECTMIN(id) FROM Person GROUPBY email )AS temp); -- need to have a outer SELECT to create a new table, -- otherwise it wll delete from itself, error
# Write your MySQL query statement below SELECT w.id FROM Weather w WHERE w.temperature > ( SELECT e.temperature FROM Weather e WHERE DATEDIFF(w.recordDate, e.recordDate) =1 );
1 2 3 4 5 6 7 8
SELECT weather.id AS'Id' FROM weather JOIN weather w ON DATEDIFF(weather.recordDate, w.recordDate) =1 AND weather.Temperature > w.Temperature ;
SELECTDISTINCT a.seat_id FROM Cinema a JOIN Cinema b ON (a.seat_id - b.seat_id =1OR b.seat_id - a.seat_id =1) AND (a.free =trueAND b.free =true) ORDERBY a.seat_id;
SELECT*,IF(x+y>z AND x+z>y AND y+z>x, 'Yes', 'No') AS'triangle' FROM triangle;
CASE
1 2 3 4 5 6 7
SELECT*, (CASE WHEN x + y > z AND x + z > y AND y + z > x THEN'Yes' ELSE'No' END) AS'triangle' FROM triangle;
UNION
1 2 3 4 5 6 7 8
-- WA... SELECT x,y,z,'No'AS'triangle' FROM Triangle WHERE x+y<=z OR x+z<=y OR y+z<=x UNION SELECT x,y,z,'Yes'AS'triangle' FROM Triangle WHERE x+y>z AND x+z>y AND y+z>x;
WITH T AS ( SELECT seller_id as id, SUM(price) AS s FROM Sales GROUPBY seller_id )
SELECT id AS seller_id FROM T WHERE s = ( SELECTMAX(s) FROM T );
OR
1 2 3 4 5 6 7 8 9 10 11
SELECT id AS seller_id FROM ( SELECT seller_id as id, SUM(price) AS s FROM Sales GROUPBY seller_id ) AS T WHERE s >=ALL( SELECTSUM(price) AS s FROM Sales GROUPBY seller_id );
SELECT b.buyer_id FROM Product AS a JOIN Sales AS b ON a.product_id = b.product_id GROUPBY b.buyer_id HAVINGSUM(a.product_name ='S8') >0andSUM(a.product_name ='iPhone') =0;