Basic SQL
sql oneline -> https:
CREATE TABLE months(id int NOT NULL, name varchar(10), days int, PRIMARY KEY (id));
INSERT INTO months VALUES (1,'January',31);
INSERT INTO months (id,name,days) VALUES (2,'February',29);
SELECT * FROM "characters"
SELECT name, weapon FROM "characters" ORDER BY name DESC
SELECT * FROM "characters" WHERE weapon = "pistol";
SELECT * FROM albums WHERE genre = 'rock' AND sales_in_millions <= 50 ORDER BY released
SELECT * FROM albums WHERE genre IN ('pop','soul');
SELECT * FROM albums WHERE released BETWEEN 1975 AND 1985;
SELECT * FROM Customers WHERE CustomerName LIKE 'a%';
SELECT MAX(released) FROM albums;
SELECT artist,album,released FROM albums
WHERE released = (SELECT MIN(released) FROM albums);
SELECT video_games.name, video_games.genre, game_developers.name,
game_developers.country FROM video_games
INNER JOIN game_developers
ON video_games.developer_id = game_developers.id;
SELECT games.name, games.genre, devs.name AS developer, devs.country
FROM video_games AS games
INNER JOIN game_developers AS devs
ON games.developer_id = devs.id;
UPDATE tv_series SET genre = 'drama' WHERE id = 2;
DELETE FROM tv_series WHERE id = 4
TRUNCATE TABLE table_name; -> delete all the rows of the table
DROP TABLE table_name; -> delete the table
SELECT car_make, car_model, car_price,
AVG(car_price) OVER() AS "overall average price",
AVG(car_price) OVER (PARTITION BY car_type) AS "car type average price"
FROM car_list_prices
SELECT car_make,
AVG(car_price) AS average_price,
MAX(car_price) AS top_price
FROM car_list_prices
GROUP BY car_make
SELECT userId FROM football
UNION
SELECT userId FROM baseball;
sql practice -> https:
->https: