-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeatAnalysis.sql
52 lines (44 loc) · 1.04 KB
/
MeatAnalysis.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
-- define the table
CREATE TABLE MeatData
(id serial,
location varchar,
indicator varchar,
subject varchar,
measure varchar,
frequency varchar,
time varchar,
value numeric
);
-- describe the table
\d meatdata
-- load in the csv of the DATA
COPY meatdata(id, location, indicator, subject, measure, frequency, time, value) -- copy into the meatdata table
FROM '/Users/kollintrujillo/Downloads/meat_consumption.csv' -- put your own directory to the file here.
DELIMITER ','
CSV HEADER;
-- will read COUNT 12160 if successful.
-- List the meat types we have in the dataset
SELECT DISTINCT subject
FROM meatdata;
-- Get value with Group by meat TYPE.
SELECT SUM(value),
subject
FROM meatdata
GROUP BY subject;
-- Get meat consumption per location, which is country
SELECT SUM(value),
subject
FROM meatdata
GROUP BY subject,
location;
-- Total meat consumption in kg per capita per country
SELECT location,
subject,
measure,
SUM(value)
FROM meatdata
WHERE measure = 'KG_CAP'
GROUP BY subject,
location,
measure
ORDER BY location;