-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholap demo.sql
32 lines (28 loc) · 1.45 KB
/
olap demo.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
-- 1
select count(*), name, state, year
from ufo_facts f inner join shapes s on s.id = f.shape_id inner join locations l on l.id = f.location_id inner join reported_dates d on d.id = f.reported_date_id
where name like 'circle' and state like 'ON' and year = 2013
group by name, state, year;
-- 2
select count(*), state
from ufo_facts f inner join shapes s on s.id = f.shape_id inner join locations l on l.id = f.location_id inner join reported_dates d on d.id = f.reported_date_id
where ((name = 'circle' and state = 'ON') or (name = 'sphere' and state = 'QC')) and year = 2014
group by state;
-- 3
SELECT city
from ufo_facts f inner join shapes s on s.id = f.shape_id inner join locations l on l.id = f.location_id inner join reported_dates d on d.id = f.reported_date_id
where country = 'USA' and name = 'sphere' and date_part('dow', d.reported_date) in (0, 5, 6)
group by city
order by count(*) desc
limit 5;
-- 4
select count(*), year, country
from ufo_facts f inner join shapes s on s.id = f.shape_id inner join reported_dates d on d.id = f.reported_date_id inner join locations l on l.id = f.location_id
where name = 'light' and year > 2010 and region like 'North America'
group by grouping sets ((year, country), (country), (year))
order by country, year, 1;
-- 5
select count(*), year
from ufo_facts f inner join shapes s on s.id = f.shape_id inner join reported_dates d on d.id = f.reported_date_id inner join locations l on l.id = f.location_id
group by year
order by year;