Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. .output stdout
  2. create table data
  3. (
  4. date_id timestamp
  5. primary key,
  6. month int
  7. )
  8. ;
  9.  
  10. create table song
  11. (
  12. song_id varchar(18)
  13. primary key,
  14. artist varchar(256),
  15. title varchar(256)
  16. )
  17. ;
  18.  
  19. create table fact_table
  20. (
  21. track_id integer
  22. primary key
  23. autoincrement,
  24. song_id varchar(18)
  25. constraint fact_table2_song_fk
  26. references song,
  27. user_id varchar(40),
  28. date_id timestamp
  29. constraint fact_table2_date_fk
  30. references data
  31. )
  32. ;
  33.  
  34. create table playbacks
  35. (
  36. user_id varchar(40),
  37. song_id varchar(18),
  38. date_id timestamp
  39. )
  40. ;
  41.  
  42. create table tracks
  43. (
  44. track_id varchar(18) not null
  45. primary key,
  46. song_id varchar(18) not null,
  47. artist varchar(256) default NULL,
  48. title varchar(256) default NULL
  49. )
  50. ;
  51.  
  52. .separator ,
  53. .import unique_tracks.txt tracks
  54.  
  55. .separator ,
  56. .import triplets_sample_20p.txt playbacks
  57.  
  58. insert into fact_table(song_id, user_id, date_id)
  59. select playbacks.song_id, user_id, date_id
  60. from playbacks left join tracks on playbacks.song_id = tracks.song_id;
  61.  
  62. insert into song
  63. select song_id, artist, title
  64. from tracks group by song_id;
  65.  
  66. insert into data
  67. select date_id, strftime("%m", datetime(date_id, 'unixepoch'))
  68. from playbacks group by date_id;
  69.  
  70. -- drop table tracks;
  71. -- drop table playbacks;
  72.  
  73. .separator ' '
  74. select title, artist, cnt
  75. from (select song_id, count(*) as cnt from fact_table group by song_id order by count(song_id) desc limit 10) as rank
  76. inner join song on rank.song_id=song.song_id;
  77. -- You're The One Dwight Yoakam 145267
  78. -- Undo Bj�rk 129778
  79. -- Revelry Kings Of Leon 105162
  80. -- Sehr kosmisch Harmonia 84981
  81. -- Horn Concerto No. 4 in E flat K495: II. Romance (Andante cantabile) Barry Tuckwell/Academy of St Martin-in-the-Fields/Sir Neville Marriner 77632
  82. -- Dog Days Are Over (Radio Edit) Florence + The Machine 71300
  83. -- Secrets OneRepublic 58472
  84. -- Use Somebody Kings Of Leon 58458
  85. -- Canada Five Iron Frenzy 54655
  86. -- Invalid Tub Ring 53494
  87.  
  88.  
  89. select user_id, count(distinct song_id)
  90. from fact_table group by user_id order by count(distinct song_id) desc limit 10;
  91. -- ec6dfcf19485cb011e0b22637075037aae34cf26 1040
  92. -- 119b7c88d58d0c6eb051365c103da5caf817bea6 641
  93. -- b7c24f770be6b802805ac0e2106624a517643c17 637
  94. -- 4e73d9e058d2b1f2dba9c1fe4a8f416f9f58364f 592
  95. -- d7d2d888ae04d16e994d6964214a1de81392ee04 586
  96. -- 6d625c6557df84b60d90426c0116138b617b9449 584
  97. -- 113255a012b2affeab62607563d03fbdf31b08e7 561
  98. -- c1255748c06ee3f6440c51c439446886c7807095 547
  99. -- db6a78c78c9239aba33861dae7611a6893fb27d5 529
  100. -- 99ac3d883681e21ea68071019dba828ce76fe94d 499
  101.  
  102.  
  103. select artist, count(*)
  104. from fact_table join song s on fact_table.song_id = s.song_id
  105. group by artist order by count(*) desc limit 1;
  106. -- Kings Of Leon 230846
  107.  
  108.  
  109. select month, count(*)
  110. from fact_table join data d on fact_table.date_id = d.date_id
  111. group by month order by month asc;
  112. -- 1 2412154
  113. -- 2 2195895
  114. -- 3 2413551
  115. -- 4 2337779
  116. -- 5 2417027
  117. -- 6 2334905
  118. -- 7 2412210
  119. -- 8 2413409
  120. -- 9 2337837
  121. -- 10 2413621
  122. -- 11 2335127
  123. -- 12 2396553
  124.  
  125.  
  126. select user_id
  127. from fact_table where song_id in (select f.song_id
  128. from (select * from fact_table group by song_id order by count(*) desc limit 2000) f inner join song
  129. where f.song_id = song.song_id and song.artist = 'Queen'
  130. group by f.song_id
  131. order by count(f.song_id)
  132. desc limit 3)
  133. group by user_id
  134. having count(distinct fact_table.song_id) >= 3
  135. order by user_id
  136. limit 10;
  137. -- ebae91ba3fa0f74003113db635b8733401e78eef
  138. -- d0bbd36f1d5543af0d08347d919811094d1c1357
  139. -- 8dd090f036cdb6940b4d18b79387db6789e6deda
  140. -- 67e48469cdb146b0abbc0810d82cf0a6160030a6
  141. -- 85ed8bc5bc1a6c4cd06efaa6f73f06ae1f4e101f
  142. -- a4b4ee9767ccab25adae784b1d6cff75fc3a133b
  143. -- 00832bf55ed890afeb2b163024fbcfaf58803098
  144. -- 215e9dd4935737010daff9e7d014d530cc1eab41
  145. -- 3456be91da73360b9197a554a8e07754720fb044
  146. -- 7f378eb82733fe2975efa4acf82f94a87ac6f8c6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement