Skip to content

Instantly share code, notes, and snippets.

@lalinsky
Created May 21, 2013 08:43
Show Gist options
  • Save lalinsky/5618390 to your computer and use it in GitHub Desktop.
Save lalinsky/5618390 to your computer and use it in GitHub Desktop.
create temporary table track_ac_count as select artist_credit, count(*) from track group by artist_credit;
create temporary table release_ac_count as select artist_credit, count(*) from release group by artist_credit;
create temporary table release_group_ac_count as select artist_credit, count(*) from release_group group by artist_credit;
create temporary table recording_ac_count as select artist_credit, count(*) from recording group by artist_credit;
create temporary table artist_credit_new as
select
artist_credit.id,
artist_credit.name,
artist_credit.artist_count,
coalesce(track_ac_count.count, 0) + coalesce(release_ac_count.count, 0) + coalesce(release_group_ac_count.count, 0) + coalesce(recording_ac_count.count, 0) AS ref_count,
artist_credit.created
from
artist_credit
left join track_ac_count on track_ac_count.artist_credit=artist_credit.id
left join release_ac_count on release_ac_count.artist_credit=artist_credit.id
left join release_group_ac_count on release_group_ac_count.artist_credit=artist_credit.id
left join recording_ac_count on recording_ac_count.artist_credit=artist_credit.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment