Skip to content

Instantly share code, notes, and snippets.

@lfy79001
Created May 28, 2024 05:56
Show Gist options
  • Save lfy79001/83fa72a46cc5aedb23d381f514c09cf4 to your computer and use it in GitHub Desktop.
Save lfy79001/83fa72a46cc5aedb23d381f514c09cf4 to your computer and use it in GitHub Desktop.
SELECT
state_code,
evaluation_group,
evaluation_description,
state_name,
sum(macroplot_acres) + sum(subplot_acres) as total_acres,
latest
FROM (SELECT
state_code,
evaluation_group,
evaluation_description,
state_name,
macroplot_acres,
subplot_acres,
MAX(evaluation_group) OVER (PARTITION By state_code) as latest
FROM `bigquery-public-data.usfs_fia.estimated_timberland_acres` )
WHERE evaluation_group = latest
GROUP by state_code, state_name, evaluation_description, evaluation_group, latest
order by state_name
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment