Guest User

Number of Steem User Accounts by Country [by @ekonugraha]

a guest
Dec 20th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.63 KB | None | 0 0
  1. CREATE TABLE #Country (
  2. CountryName VARCHAR(50)
  3. );
  4.  
  5. INSERT INTO #country (CountryName) VALUES ('Afghanistan');
  6. INSERT INTO #country (CountryName) VALUES ('Albania');
  7. INSERT INTO #country (CountryName) VALUES ('Algeria');
  8. INSERT INTO #country (CountryName) VALUES ('American Samoa');
  9. INSERT INTO #country (CountryName) VALUES ('Andorra');
  10. INSERT INTO #country (CountryName) VALUES ('Angola');
  11. INSERT INTO #country (CountryName) VALUES ('Anguilla');
  12. INSERT INTO #country (CountryName) VALUES ('Antigua and Barbuda');
  13. INSERT INTO #country (CountryName) VALUES ('Argentina');
  14. INSERT INTO #country (CountryName) VALUES ('Armenia');
  15. INSERT INTO #country (CountryName) VALUES ('Aruba');
  16. INSERT INTO #country (CountryName) VALUES ('Australia');
  17. INSERT INTO #country (CountryName) VALUES ('Austria');
  18. INSERT INTO #country (CountryName) VALUES ('Aland Islands');
  19. INSERT INTO #country (CountryName) VALUES ('Azerbaijan');
  20. INSERT INTO #country (CountryName) VALUES ('Bahamas');
  21. INSERT INTO #country (CountryName) VALUES ('Bahrain');
  22. INSERT INTO #country (CountryName) VALUES ('Bangladesh');
  23. INSERT INTO #country (CountryName) VALUES ('Barbados');
  24. INSERT INTO #country (CountryName) VALUES ('Belarus');
  25. INSERT INTO #country (CountryName) VALUES ('Belgium');
  26. INSERT INTO #country (CountryName) VALUES ('Belize');
  27. INSERT INTO #country (CountryName) VALUES ('Benin');
  28. INSERT INTO #country (CountryName) VALUES ('Bermuda');
  29. INSERT INTO #country (CountryName) VALUES ('Bhutan');
  30. INSERT INTO #country (CountryName) VALUES ('Bolivia');
  31. INSERT INTO #country (CountryName) VALUES ('Bosnia and Herzegovina');
  32. INSERT INTO #country (CountryName) VALUES ('Botswana');
  33. INSERT INTO #country (CountryName) VALUES ('Brazil');
  34. INSERT INTO #country (CountryName) VALUES ('British Virgin Islands');
  35. INSERT INTO #country (CountryName) VALUES ('Brunei');
  36. INSERT INTO #country (CountryName) VALUES ('Bulgaria');
  37. INSERT INTO #country (CountryName) VALUES ('Burkina Faso');
  38. INSERT INTO #country (CountryName) VALUES ('Burundi');
  39. INSERT INTO #country (CountryName) VALUES ('Cambodia');
  40. INSERT INTO #country (CountryName) VALUES ('Cameroon');
  41. INSERT INTO #country (CountryName) VALUES ('Canada');
  42. INSERT INTO #country (CountryName) VALUES ('Cape Verde');
  43. INSERT INTO #country (CountryName) VALUES ('Cayman Islands');
  44. INSERT INTO #country (CountryName) VALUES ('Central African Republic');
  45. INSERT INTO #country (CountryName) VALUES ('Chad');
  46. INSERT INTO #country (CountryName) VALUES ('China');
  47. INSERT INTO #country (CountryName) VALUES ('Christmas Island');
  48. INSERT INTO #country (CountryName) VALUES ('Cocos Islands');
  49. INSERT INTO #country (CountryName) VALUES ('Colombia');
  50. INSERT INTO #country (CountryName) VALUES ('Comoros');
  51. INSERT INTO #country (CountryName) VALUES ('Congo');
  52. INSERT INTO #country (CountryName) VALUES ('Cook Islands');
  53. INSERT INTO #country (CountryName) VALUES ('Costa Rica');
  54. INSERT INTO #country (CountryName) VALUES ('Côte Ivoire');
  55. INSERT INTO #country (CountryName) VALUES ('Crimea');
  56. INSERT INTO #country (CountryName) VALUES ('Croatia');
  57. INSERT INTO #country (CountryName) VALUES ('Cuba');
  58. INSERT INTO #country (CountryName) VALUES ('Curaçao');
  59. INSERT INTO #country (CountryName) VALUES ('Cyprus');
  60. INSERT INTO #country (CountryName) VALUES ('Czech');
  61. INSERT INTO #country (CountryName) VALUES ('Denmark');
  62. INSERT INTO #country (CountryName) VALUES ('Djibouti');
  63. INSERT INTO #country (CountryName) VALUES ('Dominica');
  64. INSERT INTO #country (CountryName) VALUES ('East Timor');
  65. INSERT INTO #country (CountryName) VALUES ('Ecuador');
  66. INSERT INTO #country (CountryName) VALUES ('Egypt');
  67. INSERT INTO #country (CountryName) VALUES ('El Salvador');
  68. INSERT INTO #country (CountryName) VALUES ('Equatorial Guinea');
  69. INSERT INTO #country (CountryName) VALUES ('Eritrea');
  70. INSERT INTO #country (CountryName) VALUES ('Estonia');
  71. INSERT INTO #country (CountryName) VALUES ('Ethiopia');
  72. INSERT INTO #country (CountryName) VALUES ('Falkland Islands');
  73. INSERT INTO #country (CountryName) VALUES ('Faroe Islands');
  74. INSERT INTO #country (CountryName) VALUES ('Fiji');
  75. INSERT INTO #country (CountryName) VALUES ('Finland');
  76. INSERT INTO #country (CountryName) VALUES ('France');
  77. INSERT INTO #country (CountryName) VALUES ('French Polynesia');
  78. INSERT INTO #country (CountryName) VALUES ('Gabon');
  79. INSERT INTO #country (CountryName) VALUES ('The Gambia');
  80. INSERT INTO #country (CountryName) VALUES ('Georgia');
  81. INSERT INTO #country (CountryName) VALUES ('German');
  82. INSERT INTO #country (CountryName) VALUES ('Ghana');
  83. INSERT INTO #country (CountryName) VALUES ('Gibraltar');
  84. INSERT INTO #country (CountryName) VALUES ('Greece');
  85. INSERT INTO #country (CountryName) VALUES ('Greenland');
  86. INSERT INTO #country (CountryName) VALUES ('Grenada');
  87. INSERT INTO #country (CountryName) VALUES ('Guadeloupe');
  88. INSERT INTO #country (CountryName) VALUES ('Guam');
  89. INSERT INTO #country (CountryName) VALUES ('Guatemala');
  90. INSERT INTO #country (CountryName) VALUES ('Guernsey');
  91. INSERT INTO #country (CountryName) VALUES ('Guinea');
  92. INSERT INTO #country (CountryName) VALUES ('Guinea-Bissau');
  93. INSERT INTO #country (CountryName) VALUES ('Guyana');
  94. INSERT INTO #country (CountryName) VALUES ('Haiti');
  95. INSERT INTO #country (CountryName) VALUES ('Honduras');
  96. INSERT INTO #country (CountryName) VALUES ('Hong Kong');
  97. INSERT INTO #country (CountryName) VALUES ('Hungary');
  98. INSERT INTO #country (CountryName) VALUES ('Iceland');
  99. INSERT INTO #country (CountryName) VALUES ('India');
  100. INSERT INTO #country (CountryName) VALUES ('Indonesia');
  101. INSERT INTO #country (CountryName) VALUES ('Iran');
  102. INSERT INTO #country (CountryName) VALUES ('Iraq');
  103. INSERT INTO #country (CountryName) VALUES ('Ireland');
  104. INSERT INTO #country (CountryName) VALUES ('Isle of Man');
  105. INSERT INTO #country (CountryName) VALUES ('Israel');
  106. INSERT INTO #country (CountryName) VALUES ('Italy');
  107. INSERT INTO #country (CountryName) VALUES ('Jamaica');
  108. INSERT INTO #country (CountryName) VALUES ('Japan');
  109. INSERT INTO #country (CountryName) VALUES ('Jersey');
  110. INSERT INTO #country (CountryName) VALUES ('Jordan');
  111. INSERT INTO #country (CountryName) VALUES ('Kazakhstan');
  112. INSERT INTO #country (CountryName) VALUES ('Kenya');
  113. INSERT INTO #country (CountryName) VALUES ('Kiribati');
  114. INSERT INTO #country (CountryName) VALUES ('North Korea');
  115. INSERT INTO #country (CountryName) VALUES ('South Korea');
  116. INSERT INTO #country (CountryName) VALUES ('Kosovo');
  117. INSERT INTO #country (CountryName) VALUES ('Kuwait');
  118. INSERT INTO #country (CountryName) VALUES ('Kyrgyzstan');
  119. INSERT INTO #country (CountryName) VALUES ('Laos');
  120. INSERT INTO #country (CountryName) VALUES ('Latvia');
  121. INSERT INTO #country (CountryName) VALUES ('Lebanon');
  122. INSERT INTO #country (CountryName) VALUES ('Lesotho');
  123. INSERT INTO #country (CountryName) VALUES ('Liberia');
  124. INSERT INTO #country (CountryName) VALUES ('Libya');
  125. INSERT INTO #country (CountryName) VALUES ('Liechtenstein');
  126. INSERT INTO #country (CountryName) VALUES ('Lithuania');
  127. INSERT INTO #country (CountryName) VALUES ('Luxembourg');
  128. INSERT INTO #country (CountryName) VALUES ('Macedonia');
  129. INSERT INTO #country (CountryName) VALUES ('Madagascar');
  130. INSERT INTO #country (CountryName) VALUES ('Malawi');
  131. INSERT INTO #country (CountryName) VALUES ('Malaysia');
  132. INSERT INTO #country (CountryName) VALUES ('Maldives');
  133. INSERT INTO #country (CountryName) VALUES ('Mali');
  134. INSERT INTO #country (CountryName) VALUES ('Malta');
  135. INSERT INTO #country (CountryName) VALUES ('Marshall Islands');
  136. INSERT INTO #country (CountryName) VALUES ('Martinique');
  137. INSERT INTO #country (CountryName) VALUES ('Mauritania');
  138. INSERT INTO #country (CountryName) VALUES ('Mauritius');
  139. INSERT INTO #country (CountryName) VALUES ('Mayotte');
  140. INSERT INTO #country (CountryName) VALUES ('Mexico');
  141. INSERT INTO #country (CountryName) VALUES ('Federated States of Micronesia');
  142. INSERT INTO #country (CountryName) VALUES ('Moldova');
  143. INSERT INTO #country (CountryName) VALUES ('Monaco');
  144. INSERT INTO #country (CountryName) VALUES ('Mongolia');
  145. INSERT INTO #country (CountryName) VALUES ('Montenegro');
  146. INSERT INTO #country (CountryName) VALUES ('Montserrat');
  147. INSERT INTO #country (CountryName) VALUES ('Morocco');
  148. INSERT INTO #country (CountryName) VALUES ('Mozambique');
  149. INSERT INTO #country (CountryName) VALUES ('Myanmar');
  150. INSERT INTO #country (CountryName) VALUES ('Namibia');
  151. INSERT INTO #country (CountryName) VALUES ('Nauru');
  152. INSERT INTO #country (CountryName) VALUES ('Nepal');
  153. INSERT INTO #country (CountryName) VALUES ('Netherland');
  154. INSERT INTO #country (CountryName) VALUES ('New Caledonia');
  155. INSERT INTO #country (CountryName) VALUES ('New Zealand');
  156. INSERT INTO #country (CountryName) VALUES ('Nicaragua');
  157. INSERT INTO #country (CountryName) VALUES ('Nigeria');
  158. INSERT INTO #country (CountryName) VALUES ('Niue');
  159. INSERT INTO #country (CountryName) VALUES ('Norfolk Island');
  160. INSERT INTO #country (CountryName) VALUES ('Northern Mariana Islands');
  161. INSERT INTO #country (CountryName) VALUES ('Norway');
  162. INSERT INTO #country (CountryName) VALUES ('Oman');
  163. INSERT INTO #country (CountryName) VALUES ('Pakistan');
  164. INSERT INTO #country (CountryName) VALUES ('Palau');
  165. INSERT INTO #country (CountryName) VALUES ('Palestine');
  166. INSERT INTO #country (CountryName) VALUES ('Panama');
  167. INSERT INTO #country (CountryName) VALUES ('Papua New Guinea');
  168. INSERT INTO #country (CountryName) VALUES ('Paraguay');
  169. INSERT INTO #country (CountryName) VALUES ('Peru');
  170. INSERT INTO #country (CountryName) VALUES ('Philippines');
  171. INSERT INTO #country (CountryName) VALUES ('Pitcairn Islands');
  172. INSERT INTO #country (CountryName) VALUES ('Poland');
  173. INSERT INTO #country (CountryName) VALUES ('Portugal');
  174. INSERT INTO #country (CountryName) VALUES ('Puerto Rico');
  175. INSERT INTO #country (CountryName) VALUES ('Qatar');
  176. INSERT INTO #country (CountryName) VALUES ('Réunion');
  177. INSERT INTO #country (CountryName) VALUES ('Romania');
  178. INSERT INTO #country (CountryName) VALUES ('Russia');
  179. INSERT INTO #country (CountryName) VALUES ('Rwanda');
  180. INSERT INTO #country (CountryName) VALUES ('Sahrawi');
  181. INSERT INTO #country (CountryName) VALUES ('Saint Barthélemy');
  182. INSERT INTO #country (CountryName) VALUES ('Saint Helena');
  183. INSERT INTO #country (CountryName) VALUES ('Ascension');
  184. INSERT INTO #country (CountryName) VALUES ('Tristan da Cunha');
  185. INSERT INTO #country (CountryName) VALUES ('Saint Kitts');
  186. INSERT INTO #country (CountryName) VALUES ('Nevis');
  187. INSERT INTO #country (CountryName) VALUES ('Saint Martin');
  188. INSERT INTO #country (CountryName) VALUES ('Saint Lucia');
  189. INSERT INTO #country (CountryName) VALUES ('Saint Pierre');
  190. INSERT INTO #country (CountryName) VALUES ('Miquelon');
  191. INSERT INTO #country (CountryName) VALUES ('Saint Vincent');
  192. INSERT INTO #country (CountryName) VALUES ('Grenadines');
  193. INSERT INTO #country (CountryName) VALUES ('Samoa');
  194. INSERT INTO #country (CountryName) VALUES ('San Marino');
  195. INSERT INTO #country (CountryName) VALUES ('São Tomé');
  196. INSERT INTO #country (CountryName) VALUES ('Príncipe');
  197. INSERT INTO #country (CountryName) VALUES ('Saudi Arabia');
  198. INSERT INTO #country (CountryName) VALUES ('Senegal');
  199. INSERT INTO #country (CountryName) VALUES ('Serbia');
  200. INSERT INTO #country (CountryName) VALUES ('Seychelles');
  201. INSERT INTO #country (CountryName) VALUES ('Sierra Leone');
  202. INSERT INTO #country (CountryName) VALUES ('Singapore');
  203. INSERT INTO #country (CountryName) VALUES ('Sint Maarten');
  204. INSERT INTO #country (CountryName) VALUES ('Slovakia');
  205. INSERT INTO #country (CountryName) VALUES ('Solomon Island');
  206. INSERT INTO #country (CountryName) VALUES ('Somalia');
  207. INSERT INTO #country (CountryName) VALUES ('South Africa');
  208. INSERT INTO #country (CountryName) VALUES ('South Sudan');
  209. INSERT INTO #country (CountryName) VALUES ('Spain');
  210. INSERT INTO #country (CountryName) VALUES ('Sri Lanka');
  211. INSERT INTO #country (CountryName) VALUES ('Sudan');
  212. INSERT INTO #country (CountryName) VALUES ('Suriname');
  213. INSERT INTO #country (CountryName) VALUES ('Svalbard');
  214. INSERT INTO #country (CountryName) VALUES ('Swaziland');
  215. INSERT INTO #country (CountryName) VALUES ('Sweden');
  216. INSERT INTO #country (CountryName) VALUES ('Switzerland');
  217. INSERT INTO #country (CountryName) VALUES ('Syria');
  218. INSERT INTO #country (CountryName) VALUES ('Taiwan');
  219. INSERT INTO #country (CountryName) VALUES ('Tajikistan');
  220. INSERT INTO #country (CountryName) VALUES ('Tanzania');
  221. INSERT INTO #country (CountryName) VALUES ('Thailand');
  222. INSERT INTO #country (CountryName) VALUES ('Togo');
  223. INSERT INTO #country (CountryName) VALUES ('Tokelau');
  224. INSERT INTO #country (CountryName) VALUES ('Tonga');
  225. INSERT INTO #country (CountryName) VALUES ('Trinidad');
  226. INSERT INTO #country (CountryName) VALUES ('Tobago');
  227. INSERT INTO #country (CountryName) VALUES ('Tunisia');
  228. INSERT INTO #country (CountryName) VALUES ('Turkey');
  229. INSERT INTO #country (CountryName) VALUES ('Turkmenistan');
  230. INSERT INTO #country (CountryName) VALUES ('Turks');
  231. INSERT INTO #country (CountryName) VALUES ('Caicos Island');
  232. INSERT INTO #country (CountryName) VALUES ('Tuvalu');
  233. INSERT INTO #country (CountryName) VALUES ('Uganda');
  234. INSERT INTO #country (CountryName) VALUES ('Ukraine');
  235. INSERT INTO #country (CountryName) VALUES ('United Arab Emirates');
  236. INSERT INTO #country (CountryName) VALUES ('United Kingdom');
  237. INSERT INTO #country (CountryName) VALUES ('United States');
  238. INSERT INTO #country (CountryName) VALUES ('Virgin Island');
  239. INSERT INTO #country (CountryName) VALUES ('Uruguay');
  240. INSERT INTO #country (CountryName) VALUES ('Uzbekistan');
  241. INSERT INTO #country (CountryName) VALUES ('Vanuatu');
  242. INSERT INTO #country (CountryName) VALUES ('Vatican');
  243. INSERT INTO #country (CountryName) VALUES ('Venezuela');
  244. INSERT INTO #country (CountryName) VALUES ('Vietnam');
  245. INSERT INTO #country (CountryName) VALUES ('Wallis');
  246. INSERT INTO #country (CountryName) VALUES ('Futuna');
  247. INSERT INTO #country (CountryName) VALUES ('Yemen');
  248. INSERT INTO #country (CountryName) VALUES ('Zambia');
  249. INSERT INTO #country (CountryName) VALUES ('Zimbabwe');
  250.  
  251.  
  252.  
  253. SELECT COUNT(DISTINCT a.username) as TotalUsers,CountryName FROM (
  254. SELECT name as username, CountryName FROM dbo.Accounts
  255. INNER JOIN #country ON dbo.Accounts.json_metadata LIKE '%' + #country.CountryName + '%'
  256. UNION
  257. SELECT u.username, CountryName FROM
  258. (
  259. SELECT author as username, CountryName from dbo.Comments
  260. INNER JOIN #country ON dbo.Comments.json_metadata LIKE '%introduceyourself%'
  261. WHERE depth=0 AND category = #country.CountryName
  262. GROUP BY author, CountryName
  263. UNION
  264. SELECT author as username, CountryName from dbo.Comments
  265. INNER JOIN #country ON dbo.Comments.json_metadata LIKE '%' + #country.CountryName + '%'
  266. WHERE depth=0 AND category = 'introduceyourself'
  267. GROUP BY author, CountryName
  268. ) u
  269. ) a
  270. GROUP BY CountryName
  271. ORDER BY TotalUsers DESC
Add Comment
Please, Sign In to add comment