-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL Query Basics.sql
More file actions
58 lines (45 loc) · 1.4 KB
/
SQL Query Basics.sql
File metadata and controls
58 lines (45 loc) · 1.4 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
-- Write a query to display the names of those students
--that are between the ages of 18 and 20.
SELECT student_name
FROM students
WHERE age BETWEEN 18 AND 20;
--Write a query to display all of those students that
--contain the letters "ch" in their name or their name
--ends with the letters "nd".
SELECT student_name
FROM students
WHERE student_name LIKE '%ch%'
OR student_name LIKE '%nd';
--Write a query to display the name of those students
--that have the letters "ae" or "ph" in their name and
--are NOT 19 years old.
SELECT student_name
FROM students
WHERE (student_name LIKE '%ae%'
OR student_name LIKE '%ph%')
AND age != 19;
SELECT *
FROM students
--Write a query that lists the names of students
--sorted by their age from largest to smallest.
SELECT student_name
FROM students
ORDER BY age DESC;
--Write a query that displays the names and ages
--of the top 4 oldest students.
SELECT student_name, age
FROM students
ORDER BY age DESC
FETCH FIRST 4 ROWS ONLY;
"""The student must not be older than age 20
if their student_no is either between 3 and
5 or their student_no is 7. Your query should
also return students older than age 20 but in
that case they must have a student_no that is
at least 4."""
SELECT *
FROM students
WHERE age <= 20
AND (student_no between 3 AND 5 OR student_no =7)
OR (age > 20 and student_no >= 4);
SELECT SUBSTRING('THIS IS TEST DATA' FROM 9) test_data_extracted