Code:food2.sql: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
* [[Code:fao2usda.csv]]
* [[Code:fao2usda.csv]]
* [[:File:sr28-collated.csv]]
* [[:File:sr28-collated.csv]]
* [[:File:PRIMARY-fao-livestock-primary.csv]]
* [[:File:fao-livestock-primary.csv]]
 


==Code==
<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
-- Analysis of the production of animal products
-- Analysis of the production of animal products --
---------------------------------------------------




Line 14: Line 15:
.mode csv
.mode csv
--  cross-reference table 2: livestock products (FAO data) with foods (USDA nutrition data):
--  cross-reference table 2: livestock products (FAO data) with foods (USDA nutrition data):
.import fao2usda.csv                             fao2usda
.import fao2usda.csv                     fao2usda
--  nutrition (USDA):
--  nutrition (USDA):
.import data/sr28-collated.csv                   usda
.import data/sr28-collated.csv           usda
--  crop production (FAO):
--  crop production (FAO):
.import data/primary/fao/livestock-primary.csv  animal
.import data/fao-livestock-primary.csv  animal
.mode list
.mode list


--## Animal products, worldwide production per capita


CREATE TABLE summary AS
CREATE TABLE summary AS
Line 44: Line 49:




-- Total animal protein and kalories
-- Total animal protein produced:
SELECT SUM(protein_grams_per_day_per_capita) FROM summary;
SELECT SUM(protein_grams_per_day_per_capita) FROM summary;
SELECT SUM(kalories_per_day_per_capita) FROM summary;
SELECT SUM(kalories_per_day_per_capita) FROM summary;
-- Meat production from all ruminants:
SELECT SUM(food_grams_per_day_per_capita),
    SUM(protein_grams_per_day_per_capita) FROM summary
WHERE Item="Meat, buffalo"
    OR Item="Meat, cattle"
    OR Item="Meat, goat"
    OR Item="Meat, sheep";
-- Milk production from all livestock species:
SELECT SUM(food_grams_per_day_per_capita)*0.9776 AS milk_mL_per_day_per_capita, -- Milk is slightly denser than water. To convert "grams" to "milliliters milk", multiply by 97.76% (according to GNU Units)
    SUM(protein_grams_per_day_per_capita) FROM summary WHERE Item LIKE "Milk%";




Line 57: Line 79:
SELECT COUNT(DISTINCT `Item`) FROM animal;
SELECT COUNT(DISTINCT `Item`) FROM animal;
SELECT COUNT(DISTINCT `Item`) FROM animal WHERE `Area`="World" AND `Element`="Production" AND `Unit`="tonnes";
SELECT COUNT(DISTINCT `Item`) FROM animal WHERE `Area`="World" AND `Element`="Production" AND `Unit`="tonnes";
-- Test that "World" is the only aggregate
SELECT SUM(`Value`) FROM animal WHERE `Area` ="World" AND `Element`="Production" AND `Unit`="tonnes";
SELECT SUM(`Value`) FROM animal WHERE `Area`<>"World" AND `Element`="Production" AND `Unit`="tonnes";
</syntaxhighlight>
</syntaxhighlight>