Repository navigation
Expand file tree
/
Copy pathMysql_task2.sql
More file actions
166 lines (118 loc) · 3.81 KB
/
Copy pathMysql_task2.sql
File metadata and controls
166 lines (118 loc) · 3.81 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
-- part A
create database ecommerce_db;
use ecommerce_db;
create table products (
product_id int primary key,
product_name varchar(100),
category varchar(50),
brand varchar(50),
price decimal(10,2),
quantity int,
city varchar(50),
status varchar(20)
);
desc products;
show tables;
-- part B
insert into products
(product_id, product_name, category, brand, price, quantity, city, status)
values
(201, 'Galaxy M55', 'Mobile', 'Samsung', 32000.00, 15, 'Pune', 'Available'),
(202, 'iPhone 15', 'Mobile', 'Apple', 65000.00, 8, 'Mumbai', 'Available'),
(203, 'Moto Edge 50', 'Mobile', 'Motorola', 28000.00, 20, 'Pune', 'Available'),
(204, 'Inspiron 15', 'Laptop', 'Dell', 58000.00, 6, 'Nashik', 'Available'),
(205, 'IdeaPad Slim 3', 'Laptop', 'Lenovo', 45000.00, 12, 'Mumbai', 'Available'),
(206, 'Galaxy Watch 6', 'Watch', 'Samsung', 22000.00, 4, 'Pune', 'Out of Stock'),
(207, 'Apple Watch SE', 'Watch', 'Apple', 30000.00, 10, 'Mumbai', 'Available'),
(208, 'Redmi Pad', 'Tablet', 'Xiaomi', 24000.00, 18, 'Pune', 'Available'),
(209, 'OnePlus Pad', 'Tablet', 'OnePlus', 35000.00, 5, 'Nashik', 'Available'),
(210, 'Bluetooth Speaker', 'Accessories', 'JBL', 7000.00, 25, 'Mumbai', 'Available');
-- part C
select * from products;
select product_name from products;
select product_name, price from products;
select product_name, category, brand, price from products;
select * from products where city = 'Pune';
select * from products where city = 'Mumbai';
select * from products where category = 'Mobile';
select * from products where category = 'Laptop';
select * from products where price > 30000;
select * from products where price < 30000;
select * from products where price = 35000;
select * from products where price >= 45000;
select * from products where price <= 30000;
select * from products where quantity > 10;
select * from products where quantity < 10;
-- part D
select * from products
where city = 'Pune' and category = 'Mobile';
select * from products
where city = 'Mumbai' and status = 'Available';
select * from products
where price > 30000 and quantity > 5;
select * from products
where price >= 30000 and price <= 60000;
select * from products
where city = 'Pune' or city = 'Mumbai';
select * from products
where category = 'Mobile' or category = 'Laptop';
select * from products
where quantity < 10 or price > 50000;
select * from products
where category = 'Mobile' and price > 30000;
select * from products
where brand = 'Samsung' or brand = 'Apple';
select * from products
where city = 'Pune' and status = 'Available' and quantity > 10;
-- part E
select * from products
where price between 25000 and 50000;
select * from products
where quantity between 5 and 15;
select * from products
where category in ('Mobile', 'Laptop', 'Tablet');
select * from products
where city in ('Pune', 'Mumbai');
select * from products
where brand not in ('Samsung');
select * from products
where status not in ('Out of Stock');
select * from products
where price != 30000;
select * from products
where product_name like 'Galaxy%';
select * from products
where product_name like '%Pad%';
select * from products
where category = 'Mobile'
and (price > 30000 or quantity > 15);
-- part F
update products
set price = 34000
where product_name = 'Galaxy M55';
update products
set quantity = 12
where product_name = 'iPhone 15';
update products
set status = 'Available'
where product_name = 'Galaxy Watch 6';
update products
set price = price + 2000
where category = 'Mobile';
update products
set quantity = quantity + 5
where city = 'Pune';
update products
set status = 'Out of Stock'
where quantity < 5;
-- part G
delete from products
where product_id = 210;
delete from products
where price < 8000;
delete from products
where status = 'Out of Stock'
and quantity < 5;
delete from products
where category = 'Tablet'
and price > 30000;