-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelect Mastery.sql
More file actions
87 lines (70 loc) · 1.7 KB
/
Select Mastery.sql
File metadata and controls
87 lines (70 loc) · 1.7 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
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
use MyDatabase;
-- select order table
select *
from orders;
-- select custo table
select *
from customers;
-- retreive custo col name, country, and score
select
first_name,
country,
score
from customers;
-- retreive custo with score not equal to 0
select *
from customers
where score != 0;
--retreive custo from germany
select *
from customers
where country = 'Germany';
-- retreive custo from germany with name and country col only
select
first_name,
country
from customers
where country = 'Germany';
-- retreive custo and sort result by highest score first
select *
from customers
order by score desc;
-- lowest first and remove 0
select *
from customers
where score != 0
order by score asc;
-- retreive custo and sort result by country and then by highest score
select *
from customers
order by
country asc,
score desc;
-- find total score for each country
select
country,
sum(score) as Total_score
from customers
group by country;
-- find total score and total custo for each country
select
country,
sum(score) as total_score,
count(id) as total_customer
from customers
group by country;
-- find avg score for each country with score not equal to 0 and return only country with average score greater than 430
select country, avg(score) as avg_score
from customers
where score != 0
group by country
having avg(score) > 430
order by avg_score desc;
--return unique list of all countries
select distinct country from customers;
--return top 3 custo with highest score
select top 3 * from customers order by score desc;
--return lowest score
select top 2 * from customers where score != 0 order by score asc;
-- return 2 most recent order
select top 2 * from orders order by order_date desc;