-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmytutorial.sql
More file actions
44 lines (31 loc) · 900 Bytes
/
mytutorial.sql
File metadata and controls
44 lines (31 loc) · 900 Bytes
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
SELECT version();
CREATE TABLE students (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
age INT,
grade VARCHAR(2)
);
-- Insert some sample student records
INSERT INTO students (name, age, grade) VALUES
('Alice Johnson', 14, 'A'),
('Bob Smith', 15, 'B'),
('Carol White', 14, 'A+');
SELECT * FROM students;
SELECT name, grade FROM students;
SELECT * FROM students WHERE age = 14;
SELECT * FROM students WHERE name LIKE 'A%'; -- Names starting with A
-- Updata students grade
UPDATE students
SET grade = 'A' WHERE name = 'Carol White'
-- delete a students based on id
DELETE FROM students
WHERE id = 2;
SELECT * FROM students;
--Count how many students got an A grade
SELECT COUNT(*) FROM students WHERE grade = 'A';
--Order by age
SELECT * FROM students ORDER BY age DESC;
--Get unique grade
SELECT DISTINCT grade FROM students;
--Permanently delete table
DROP TABLE students;