-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.sql
126 lines (108 loc) · 3.36 KB
/
queries.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
/**
SQL queries that might be of interest. Copy and paste into terminal.
To open db: sqlite3 eventdata.db
*/
/* Attendance rate for each event. */
select event_name, round(r, 4)
from (
select event_name, (cast(count(case when attendee_status like 'Checked In' then 1 end) as FLOAT) / cast(count(*) as FLOAT)) as r
from attendees
group by event_name
)
order by r desc;
/** Average attendance rate overall and variance (because sqlite doesn't have sqrt). */
select avg(r), ((sum(r)*sum(r) - sum(r * r))/((count(*)-1)*(count(*))))
from (
select event_name, (cast(count(case when attendee_status like 'Checked In' then 1 end) as FLOAT) / cast(count(*) as FLOAT)) as r
from attendees
group by event_name
)
order by r desc;
/** Events by number checked in. */
select event_name, count(*)
from attendees
where attendee_status like "Checked In"
group by event_name
order by count(*) desc;
/** Average checked in for all events. */
select avg(c)
from (
select event_name, count(*) as c
from attendees
where attendee_status like "Checked In"
group by event_name
order by count(*) desc
);
/** How did people hear about events? */
select how_did_you_hear, count(*)
from attendees
group by how_did_you_hear
order by count(*) desc;
/** Attendance rate for how people heard about events. */
select how_did_you_hear, c, round(r, 4)
from (
select how_did_you_hear, count(*) as c, (cast(count(case when attendee_status like 'Checked In' then 1 end) as FLOAT) / cast(count(*) as FLOAT)) as r
from attendees
group by how_did_you_hear
having count(*) > 5
)
order by r desc;
/** Events by signups. */
select event_name, count(*) as c
from attendees
group by event_name
order by count(*) desc;
/** Average event signups. */
select avg(c)
from (
select count(*) as c
from attendees
group by event_name
);
/** Attendees who have paid the most to attend events. */
select first_name, last_name, email, sum(total_paid)
from attendees
where total_paid > 0
group by first_name, last_name
order by sum(total_paid) desc;
/** People who have attended the most events. */
select first_name, last_name, email, count(*)
from attendees
group by first_name, last_name
order by count(*) desc;
/** Number of people who paid money for events and had a Berkeley email and how much they paid. */
select count(*), sum(total_paid)
from attendees
where email like '%@berkeley%' and total_paid > 0;
/** Total ticket sales ($). */
select sum(total_paid)
from attendees;
/** Ticket sales by event ($). */
select event_name, sum(total_paid)
from attendees
group by event_name
order by sum(total_paid) desc;
/** Number of tickets sold for each ticket type. */
select ticket_type, count(*)
from attendees
group by ticket_type
order by count(*) desc;
/** Ticket sales by IP location. */
select ip_location, count(*)
from attendees
group by ip_location
order by count(*) desc;
/** Number of people who bought tickets from IPs outside of California. */
select count(*)
from attendees
where ip_location not like '% CA, %';
/* People who bought tickets from outside CA who checked in. */
select count(*)
from attendees
where ip_location not like '% CA, %' and attendee_status like "Checked In";
/* Events by attendees from outside CA. */
select event_name, count(*)
from attendees
where ip_location not like '% CA, %' and attendee_status like "Checked In"
group by event_name
order by count(*) desc;