-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLNulls.sql
77 lines (53 loc) · 1.68 KB
/
SQLNulls.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
/**************************************************************
NULL VALUES
Works for SQLite, MySQL, Postgres
**************************************************************/
insert into Student values (432, 'Kevin', null, 1500);
insert into Student values (321, 'Lori', null, 2500);
select * from Student;
/**************************************************************
All students with high GPA
**************************************************************/
select sID, sName, GPA
from Student
where GPA > 3.5;
/*** Now low GPA ***/
select sID, sName, GPA
from Student
where GPA <= 3.5;
/*** Now either high or low GPA ***/
select sID, sName, GPA
from Student
where GPA > 3.5 or GPA <= 3.5;
/*** Now all students ***/
select sID, sName from Student;
/*** Now use 'is null' ***/
select sID, sName, GPA
from Student
where GPA > 3.5 or GPA <= 3.5 or GPA is null;
/**************************************************************
All students with high GPA or small HS
**************************************************************/
select sID, sName, GPA, sizeHS
from Student
where GPA > 3.5 or sizeHS < 1600;
/*** Add large HS ***/
select sID, sName, GPA, sizeHS
from Student
where GPA > 3.5 or sizeHS < 1600 or sizeHS >= 1600;
/**************************************************************
Number of students with non-null GPAs
**************************************************************/
select count(*)
from Student
where GPA is not null;
/*** Number of distinct GPA values among them ***/
select count(distinct GPA)
from Student
where GPA is not null;
/*** Drop non-null condition ***/
select count(distinct GPA)
from Student;
/*** Drop count ***/
select distinct GPA
from Student;