Advertisement
NonplayerCharacter

PostgreSQL | Count with unnest

Apr 7th, 2022
1,324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- https://platform.stratascratch.com/coding/10049-reviews-of-categories
  2. /* Data:
  3.  
  4.     select categories, review_count
  5.     from yelp_business
  6.     limit 3
  7.  
  8. categories                                                                                    | review_count
  9. ----------------------------------------------------------------------------------------------|-------------
  10. Auto Detailing;Automotive                                                                       4
  11. Personal Chefs;Food;Gluten-Free;Food Delivery Services;Event Planning & Services;Restaurants    27
  12. Dry Cleaning & Laundry;Laundry Services;Local Services;Dry Cleaning                             4
  13. */
  14.  
  15. select
  16.     unnest(string_to_array(categories,';')),
  17.     sum(review_count)
  18. from yelp_business
  19. group by 1
  20. order by 2 desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement