forked from harsh432004/Complete-Data-Science-with-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 15-More on SQL.sql
127 lines (94 loc) · 2 KB
/
Day 15-More on SQL.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
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
drop database test;
create database university;
use university;
create table harsh(
id int auto_increment,
name char(100) NOT NULL,
age int,
Email varchar(100) UNIQUE,
mark float not null,
primary key(id)
);
insert into harsh(name, age, email, mark)
values
("Noody",20,"nody@gmail.com",30),
("Oggy",44,"oggy@gmail.com",100),
("Sinchan",20,"sinchan@gmail.com",60),
("Doremon",20,"doremon@gmail.com",50),
("Hagemaru",20,"hagemaru@gmail.com",70);
select * from harsh
where mark >= 60;
-- Syntax for deleting the existing data
SET SQL_SAFE_UPDATES=0;
delete from compsc
where mark = 70;
-- order by (sort)
-- Asce or Desc
--
-- Syntax for sorting
-- SELECT col
-- from table compsc
-- order by col_name
-- for ascending
Select mark
from compsc
order by mark;
-- for descending
Select *
from compsc
order by mark, name;
Select *
from compsc
order by mark desc, name desc;
Select *
from compsc
order by age desc, email asc;
-- Syntax for max
-- syntax: max (col_name)
from table_name;
select min(mark)
from compsc;
select * from compsc
order by mark, name;
select * from compsc
order by mark desc, name asc;
-- Max and Min
-- syntax- max(col_name) from table_name;
select min(mark)
from compsc;
select max(name)
from compsc;
select min(mark)
from compsc
where mark > 70
select min(mark)
from compsc
-- count
select count(mark)
from harsh
where age>20;
select avg(Age)
from compsc
where mark>50;
select * from compsc;
where mark between 20 and 30;
select sum(mark)
from compsc;
select * from compsc
where mark between 20 and 30;
-- Between
select SUM(mark) from compsc
where mark between 20 and 30;
select * from compsc
where mark between 20 and 30;
select SUM(mark) from compsc
where age > 0 and mark < 100;
insert into compsc(name, age, email, mark)
values
("Noddy",20,"noddy@yahho.com",30),
("oswal",44,"oswal@zoho.com",100),
("Pingu",20,"pingu@rediffmail.com",60),
("bob",20,"bob@outlook.com",50),
("Mojo",20,"mojo@jojo.com",70);
select * from compsc
where email like 'n%m';