Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Created May 9, 2014 00:02
Show Gist options
  • Save Bondifrench/6cd683605f7fbc26c034 to your computer and use it in GitHub Desktop.
Save Bondifrench/6cd683605f7fbc26c034 to your computer and use it in GitHub Desktop.
Pivoting Finviews data, grouping by concepts, ordering by presentation order
Select
s.concept,
sum(case when s.fiscalyear =2009 then s.value else 0 end) as "2009",
sum(case when s.fiscalyear =2010 then s.value else 0 end) as "2010",
sum(case when s.fiscalyear =2011 then s.value else 0 end) as "2011",
sum(case when s.fiscalyear =2012 then s.value else 0 end) as "2012",
sum(case when s.fiscalyear =2013 then s.value else 0 end) as "2013",
sum(case when s.fiscalyear =2014 then s.value else 0 end) as "2014"
from (Select concept, fiscalyear, value, preorder from sec_sample
where cik=1288776
AND periodfocus = 'FY'
AND rootconcept = 'Statement of Income'
Order by fiscalyear, concept
) as s
group by s.concept
order by min(s.preorder);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment