Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Sports(2)
  2. Education(3)
  3. Community(0)
  4. Something(0)
  5.  
  6. SELECT
  7. AC.ACID, MAX(AC.Name) as Name,
  8. COUNT(*) as Frequency
  9. FROM
  10. Album A
  11. INNER JOIN
  12. AlbumCategories AC ON A.ACID = AC.ACID
  13. GROUP BY
  14. AC.ACID
  15.  
  16. Sports(2)
  17. Education(3)
  18.  
  19. ACID Name
  20. 1 Sports
  21. 2 Education
  22. 3 Community
  23. 4 Something
  24.  
  25. AID ACID Name
  26. 1 1 Footbal season 2015
  27. 2 1 Footbal season 2016
  28. 3 2 Album one
  29. 4 2 Album Two
  30. 5 2 Album Three
  31.  
  32. PID AID Image
  33.  
  34. CREATE TABLE AlbumCategories
  35. ([ACID] int, [Name] varchar(9))
  36. ;
  37.  
  38. INSERT INTO AlbumCategories
  39. ([ACID], [Name])
  40. VALUES
  41. (1, 'Sports'),
  42. (2, 'Education'),
  43. (3, 'Community'),
  44. (4, 'Something');
  45.  
  46.  
  47. CREATE TABLE albums
  48. ([AID] int, [ACID] int, [Name] varchar(19))
  49. ;
  50.  
  51. INSERT INTO albums
  52. ([AID], [ACID], [Name])
  53. VALUES
  54. (1, 1, 'Footbal season 2015'),
  55. (2, 1, 'Footbal season 2016'),
  56. (3, 2, 'Album one'),
  57. (4, 2, 'Album Two'),
  58. (5, 2, 'Album Three');
  59.  
  60. SELECT AC.ACID,
  61. AC.NAME AS NAME,
  62. Count(A.ACID) AS Frequency
  63. FROM albums A
  64. RIGHT JOIN AlbumCategories AC
  65. ON A.ACID = AC.ACID
  66. GROUP BY AC.ACID,
  67. AC.NAME
  68.  
  69. ╔══════╦═══════════╦═══════════╗
  70. ║ ACID ║ NAME ║ Frequency ║
  71. ╠══════╬═══════════╬═══════════╣
  72. ║ 1 ║ Sports ║ 2 ║
  73. ║ 2 ║ Education ║ 3 ║
  74. ║ 3 ║ Community ║ 0 ║
  75. ║ 4 ║ Something ║ 0 ║
  76. ╚══════╩═══════════╩═══════════╝
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement