Примеры
Compact a three-row INSERT statement
Ввод
INSERT INTO planets (name, moons)
VALUES ('Earth', 1),
('Mars', 2),
('Venus', 0);Expected answer
INSERT INTO planets(name, moons) VALUES ('Earth', 1), ('Mars', 2), ('Venus', 0);Reduce whitespace around an EXISTS subquery
Ввод
SELECT name
FROM customers
WHERE EXISTS (SELECT 1 FROM orders WHERE orders.customer_id = customers.id);Expected answer
SELECT name FROM customers WHERE EXISTS(SELECT 1 FROM orders WHERE orders.customer_id = customers.id);Keep a spaced city name inside a string literal
Ввод
SELECT station_id, city
FROM stations
WHERE city = 'New York'
ORDER BY station_id;Expected answer
SELECT station_id, city FROM stations WHERE city = 'New York' ORDER BY station_id;Compact an update with an explicit safety condition
Ввод
UPDATE inventory
SET stock = stock - 1
WHERE sku = 'BOOK-ALICE' AND stock > 0;Expected answer
UPDATE inventory SET stock = stock - 1 WHERE sku = 'BOOK-ALICE' AND stock > 0;Keep UNION ALL when combining two event streams
Ввод
SELECT occurred_at, 'signup' AS kind FROM signups
UNION ALL
SELECT occurred_at, 'purchase' AS kind FROM purchases;Expected answer
SELECT occurred_at, 'signup' AS kind FROM signups UNION ALL SELECT occurred_at, 'purchase' AS kind FROM purchases;