forked from sedenardi/snapchat-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregateQuery.sql
More file actions
48 lines (45 loc) · 971 Bytes
/
aggregateQuery.sql
File metadata and controls
48 lines (45 loc) · 971 Bytes
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
-- drop table if exists areacoderank;
-- create temporary table areacoderank as (
-- select
-- areacode,
-- state,
-- city,
-- lat,
-- lon,
-- (
-- case
-- when @curType = areacode
-- then @curRow := @curRow + 1
-- else @curRow := 1 and @curType := areacode
-- end
-- ) rank
-- from goodareacodes a,
-- (select @curRow := 0, @curType := '') r
-- order by areacode,city
-- );
drop table if exists areacodestats;
create temporary table if not exists areacodestats as (
select
substring(phone,1,3) as areacode,
count(*) as count
from records
group by areacode
);
drop table if exists jscode;
create temporary table if not exists jscode as (
select
r.areacode,
r.state,
r.city,
r.lat,
r.lon,
s.count,
CONCAT('{lat: ',r.lat,', lng: ',r.lon,', count: ',s.count,'}') as json
from goodareacodes r
inner join areacodestats s
on s.areacode = r.areacode
order by s.count desc
);
select
concat('[',group_concat(json separator ', '),']') as code
from jscode;