-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice2.sql
69 lines (55 loc) · 1.22 KB
/
practice2.sql
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
CREATE DATABASE db;
use db;
CREATE TABLE db_info(
id INT PRIMARY KEY,
name VARCHAR(50),
grade varchar(1),
marks INT NOT NULL,
city VARCHAR(20));
INSERT INTO db_info(id, name, grade, marks, city)
VALUES
(01, "sourabh", "S", 99, "SEONI"),
(02, "Ankit", "A", 95, 'Chhapra'),
(03, "Chandan", "B", 90, "Chhapara"),
(04, "Harshit", "C", 85, "Chhindwara"),
(05,"vipin", "S", 99, "Jbp");
INSERT INTO db_info value (06,"Manish", "A", 90, "CWA");
INSERT INTO db_info value (08,"Neeraj", "D", 59, "ATA");
SELECT DISTINCT city FROM db_info;
SELECT grade , count(name)
FROM db_info
group by grade order by grade desc;
SELECT city, avg(marks)
FROM db_info
GROUP BY city
ORDER BY avg(marks) ASC;
SELECT name, avg(marks)
FROM db_info
GROUP BY name
ORDER BY avg(marks) DESC;
SELECT city, count(name)
FROM db_info
GROUP BY city
HAVING max(marks)> 90;
SELECT city, count(name)
FROM db_info
WHERE grade = "A"
GROUP BY city
HAVING max(marks) >= 80
ORDER BY city ASC;
SET SQL_SAFE_UPDATES = 0;
-- UPDATE QUERIES
UPDATE db_info
SET grade = "A"
WHERE grade = "O";
UPDATE db_info
SET marks = 95
where marks = 2;
update db_info
set marks = marks+1;
-- DELETE Queries
DELETE FROM db_info
WHERE marks < 70;
DELETE FROM db_info;
SELECT * FROM db_info;
SELECT name