Repository navigation
Expand file tree
/
Copy pathSession-06.sql
More file actions
78 lines (61 loc) · 1.96 KB
/
Copy pathSession-06.sql
File metadata and controls
78 lines (61 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- SESSION 6
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100),
price DECIMAL(10, 2),
category VARCHAR(50)
);
INSERT INTO products (id, name, price, category) VALUES
(1, 'Wireless Mouse', 25.50, 'Electronics'),
(2, 'USB-C Cable', 12.99, 'Electronics'),
(3, 'Gaming Keyboard', 89.99, 'Electronics'),
(4, 'Office Chair', 150.00, 'Furniture'),
(5, 'Desk Lamp', 35.75, 'Furniture'),
(6, 'Notebook Set', 8.50, 'Stationery'),
(7, 'Bluetooth Headphones', 120.00, 'Electronics'),
(8, 'Monitor Stand', 45.00, 'Furniture');
select * from products
order by price asc ;
select * from products
order by price desc
limit 5 ;
CREATE TABLE movies (
id INT PRIMARY KEY,
title VARCHAR(150),
release_year INT,
rating DECIMAL(3, 2)
);
INSERT INTO movies (id, title, release_year, rating) VALUES
(1, 'Inception', 2010, 8.8),
(2, 'The Dark Knight', 2008, 9.0),
(3, 'Interstellar', 2014, 8.6),
(4, 'Dunkirk', 2017, 7.8),
(5, 'Tenet', 2020, 7.3),
(6, 'The Matrix', 1999, 8.7),
(7, 'Avatar', 2009, 7.9),
(8, 'Oppenheimer', 2023, 8.9);
select * from movies
order by release_year desc , rating desc ;
select * from restaurants
order by name asc
limit 10 ;
CREATE TABLE songs (
id INT PRIMARY KEY,
title VARCHAR(100),
artist VARCHAR(100),
play_count INT,
added_date DATE
);
INSERT INTO songs (id, title, artist, play_count, added_date) VALUES
(1, 'Blinding Lights', 'The Weeknd', 5000000, '2023-01-15'),
(2, 'Shape of You', 'Ed Sheeran', 4800000, '2023-02-20'),
(3, 'Levitating', 'Dua Lipa', 5000000, '2023-03-10'), -- Tie in play_count with #1, but newer
(4, 'Peaches', 'Justin Bieber', 3200000, '2023-01-05'),
(5, 'Stay', 'Kid Laroi & Bieber', 4800000, '2023-04-01'), -- Tie in play_count with #2, but newer
(6, 'Good 4 U', 'Olivia Rodrigo', 3900000, '2023-02-14'),
(7, 'Montero', 'Lil Nas X', 3500000, '2023-03-22');
select title as trending_songs
from songs
order by play_count desc , added_date desc
limit 3;
show tables ;