This ISRC is a mess, with 749 distinct track_ids GBPS81525962 This ISRC has 6 distinct track_ids USMP60060356 --## This query identifies ISRC-track_id combos with more than one track_artists SELECT isrc, track_id, count(*) as counts FROM ( SELECT isrc , track_id , track_artists FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' GROUP BY 1, 2, 3 ) GROUP BY 1, 2 HAVING counts > 1 ; --## This query identifies ISRCs with more than one track_id SELECT isrc, count(*) as counts FROM ( SELECT isrc , track_id FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' GROUP BY 1, 2 ) GROUP BY 1 HAVING counts > 1 ; --## This query identifies track_id's with more than one isrc-track_album_artist combo SELECT track_id, count(*) as counts FROM ( SELECT isrc , track_id , track_album_artist FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' GROUP BY 1, 2, 3 ) GROUP BY 1 HAVING counts > 1 ; --## This query identifies track_id's with more than one UPC --## 0 ROWS PRODUCED SELECT track_id, count(*) as counts FROM ( SELECT album_code AS UPC , track_id FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' GROUP BY 1, 2 ) GROUP BY 1 HAVING counts > 1 ; --## Each track_id should be unique per UPC+ISRC combo SELECT upc, isrc, count(*) as counts FROM ( SELECT upc , isrc , track_id FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' GROUP BY 1, 2, 3 ) GROUP BY 1, 2 HAVING counts > 1 ; --## This query gets metadata on the start-stops of the different sets of metadata for a given ISRC SELECT distinct ALBUM_CODE, ALBUM_NAME, ISRC, TRACK_ID, TRACK_URI, TRACK_NAME, TRACK_ARTISTS, TRACK_ALBUM_ARTIST, min(tmstamp) as minDate, max(tmstamp) as maxDate, COUNT (*) as streams FROM production.staging_raw_spotify_v2 WHERE isrc = 'US89R1111302' GROUP BY 1,2,3,4,5,6, 7, 8 ORDER BY minDate, maxDate; --## This query gets metadata on the start-stops of the different sets of metadata for a given ISRC SELECT distinct ALBUM_CODE, ALBUM_NAME, ISRC, TRACK_ID, TRACK_URI, TRACK_NAME, TRACK_ARTISTS, TRACK_ALBUM_ARTIST, min(tmstamp) as minDate, max(tmstamp) as maxDate, COUNT (*) as streams FROM production.staging_raw_spotify_v2 WHERE track_id = 'd41cafec05844ce0b3690516c7c8175f' GROUP BY 1,2,3,4,5,6, 7, 8 ORDER BY minDate, maxDate; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DT.upc_isrcs_with_many_Track_ids <- sfQry("SELECT upc, isrc, count(*) as counts FROM ( SELECT upc , isrc , track_id FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' GROUP BY 1, 2, 3 ) GROUP BY 1, 2 HAVING counts > 1 ;") DT.example_of_upc_isrc_with_many_track_ids <- { sfQry( DT.upc_isrcs_with_many_Track_ids[11, sprintf( "SELECT distinct UPC, ALBUM_CODE, ALBUM_NAME, ISRC, TRACK_ID, TRACK_URI, TRACK_NAME, TRACK_ARTISTS, TRACK_ALBUM_ARTIST, min(tmstamp)::date as minDate, max(tmstamp)::date as maxDate, COUNT (*) as streams FROM production.staging_raw_spotify_v2 WHERE ( upc = '%s' AND isrc = '%s' ) GROUP BY 1,2,3,4,5,6,7,8,9 ORDER BY minDate, maxDate;" , upc, isrc )] ) } DT.track_ids_with_more_than_one_upc_isrc_combo <- sfQry(" SELECT track_id, count(*) as counts FROM ( SELECT upc , isrc , track_id FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' GROUP BY 1, 2, 3 ) GROUP BY 1 HAVING counts > 1 ;") DT.example_of_track_ids_with_more_than_one_upc_isrc_combo <- { sfQry( DT.track_ids_with_more_than_one_upc_isrc_combo[1, sprintf( "SELECT distinct UPC, ALBUM_CODE, ALBUM_NAME, ISRC, TRACK_ID, TRACK_URI, TRACK_NAME, TRACK_ARTISTS, TRACK_ALBUM_ARTIST, min(tmstamp)::date as minDate, max(tmstamp)::date as maxDate, COUNT (*) as streams FROM production.staging_raw_spotify_v2 WHERE ( track_id = '%s' ) GROUP BY 1,2,3,4,5,6,7,8,9 ORDER BY minDate, maxDate;" , track_id )] ) %>% setIDCols() } DT.album_code_different_from_UPC <- sfQry(" SELECT album_code , upc , track_id , count(*) as streams FROM production.staging_raw_spotify_v2 WHERE TMSTAMP::date >= '2015-05-04' AND album_code != upc GROUP BY 1, 2, 3 ;")