-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCongressQueryProject.sql
187 lines (139 loc) · 5.78 KB
/
CongressQueryProject.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
create table res
(code varchar(5),
category varchar(50));
insert into Reasons (Code,Category)
values
('X', 'Unwanted contact'),
('A', 'Consensual scandals'),
('B', 'Other scandals'),
('C', 'Other office'),
('D', 'Private sector'),
('E', 'Health/family'),
('F', 'Other'),
('G', 'Left early'),
('H', 'Military services'),
('I', 'Election overturned')
--Cleaning up Resignation Date column
alter table congressional_resignations$
alter column resignationdate date
select *
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
select * from congressional_resignations$
select member, party, reason, source, r.Category,c.ResignationDate
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
where code in ('b','c')
group by Member,party, reason, source, r.Category,c.ResignationDate
select c.party Party, r.Category,r.code Code, count(code) NumberOfPeopleWhoResigned, TotalMembersOfParty,
cast((cast(count(code)as decimal(10,2))/cast((totalmembersofparty) as decimal(10,2))*100) as decimal (10,2)) as PercentageOfPartyWhoResigned
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
join (select party, count(member) as totalmembersofparty from congressional_resignations$ group by party) as t
on t.party = c.party
group by c.party, r.Category, r.code, totalmembersofparty
having r.code in ('a','b','c','d','e','f','g','h','i')
select c.party Party, r.Category,r.code Code, count(code) NumberOfPeopleWhoResigned, TotalMembersOfParty,
cast((cast(count(code)as decimal(10,2))/cast((totalmembersofparty) as decimal(10,2))*100) as decimal (10,2)) as PercentageOfPartyWhoResigned
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
join (select party, count(member) as totalmembersofparty from congressional_resignations$ group by party) as t
on t.party = c.party
group by c.party, r.Category, r.code, totalmembersofparty
having r.code in ('a','b','c','d','e','f','g','h','i','x')
order by c.party, r.code
select c.party, count(code) as NumberOfSexualHarassmentResignations,TotalMembersOfParty,
cast((cast(count(code)as decimal(10,2))/cast((totalmembersofparty) as decimal(10,2))*100) as decimal (10,2)) as SexualHarassmentResignationPercentageOfParty
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
join (select party, count(member) as totalmembersofparty from congressional_resignations$ group by party) as t
on t.party = c.party
where code = 'x' or code = 'a'
group by c.party, totalmembersofparty
select member, reason, source, Category,ResignationDate
from congressional_resignations$ c
where ResignationDate between '1980-01-01' and '2000-01-01'
group by Member, reason, source, Category,ResignationDate
order by ResignationDate desc
select *
from congressage ca
left join congressional_resignations$ c on c.member = concat(ca.firstname,' ',ca.lastname)
full outer join Reasons r on c.Category = r.code
select *
from congressional_resignations$ c
join Reasons r
on r.code = c.Category
where Member like 'Barack Obama'
select member, party, reason, source, r.Category,ResignationDate,congress
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
where code = 'x' or code = 'a'
group by party, member, party, reason, source, r.Category,ResignationDate,Congress
order by 2
select source, count(member) as n,ResignationDate as yearofres
from congressional_resignations$
group by source,ResignationDate
order by yearofres desc
select *
from Reasons
select party, count(code) as NumberOfSexualHarassmentResignations
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
where code = 'x' or code = 'a'
group by party
select party, r.Category, count(code) numberoftimes
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
where code = 'x' or code = 'a'
group by party, r.Category
order by Party
select r.Category, count(code) TotalResignationsPerCategory
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
where r.Category is not null
group by r.Category, r.code
order by Category
select *
from Reasons
select party, count(member) as TotalNumberOfResignations
from congressional_resignations$
group by party
select party, category,numberoftimes,totalmembers, cast((numberoftimes/totalmembers) as decimal(10,2)) as percentageofparty
from
(
select c.party, r.Category, count(code) numberoftimes, totalmembers, cast(((count(code)/totalmembers)*100) as decimal(10,2)) as percentageofparty
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
join (select party, count(member) as totalmembers from congressional_resignations$ group by party) as t
on t.party = c.party
group by c.party, r.Category, r.code, totalmembers
) x
select c.party, r.Category, count(code) numberoftimes, totalmembers, cast(((count(code)/totalmembers)*100) as decimal(10,2)) as percentageofparty
from Reasons r
full outer join congressional_resignations$ c
on r.Code = c.Category
join (select party, count(member) as totalmembers from congressional_resignations$ group by party) as t
on t.party = c.party
group by c.party, r.Category, r.code, totalmembers
select *
from congressional_resignations$
where Member like 'joe biden'
select *
from congressage ca
join congressional_resignations$ c on c.member = concat(ca.firstname,' ',ca.lastname)
full outer join Reasons r on c.Category = r.code
select *
from congressage ca
full outer join congressional_resignations$ c on c.member = concat(ca.firstname,' ',ca.lastname)
full outer join Reasons r on c.Category = r.code
where c.Member like 'barack obama'