-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLindaSQL
78 lines (70 loc) · 1.41 KB
/
LindaSQL
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
-- FOR THE LINDA PROJECT
Create table names(
nam varchar(20),
gender varchar(2),
tot int,
year int
);
-- Getting all of the Lindas
select
*
from
names
where
nam = 'Linda'
AND gender = 'F'
order by
year asc
;
-- making a new column to give me the rank of each name by each year and gender (in a CTE)
WITH ranked_names AS (
select
name
, gender
, year
, tot
, RANK() OVER (PARTITION BY year, gender ORDER BY tot DESC) AS name_rank
from baby_names
)
SELECT name, gender, year, tot, name_rank
FROM ranked_names
WHERE name_rank = 1;
-- Making a temp table for the data
create temp table ranked_names AS (
SELECT
nam
, gender
, year
, tot
, RANK() OVER (PARTITION BY year, gender ORDER BY tot DESC) AS name_rank
FROM ssnames
);
-- First graph, the sheer number of babies born with the name linda connected line graph
-- the rank graph in a like a bar thing maybe
-- contrast linda vs mary
-- a line graph with the line showing how many girls are named the most common name
-- and the color changes for each new name
-- Outlook for linda, last ten years
--The male Linda
select
*
from
ranked_names
where 1=1
and nam = 'Linda'
and gender = 'M'
order by
year asc
;
--The number one names throughout the years
select
nam
, year
, tot
from ranked_names
where 1=1
and name_rank = 1
and gender = 'F'
order by
year asc
;