Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. users: categories:
  2. ╔═══════╦═══════════╗╔═══════╦═══════════╗
  3. ║ id ║ user_type ║║ id ║ name ║
  4. ╠═══════╬═══════════╣╠═══════╬═══════════╣
  5. ║ id 1 ║ tutor ║║ id 1 ║ name1 ║
  6. ║ id 2 ║ other ║║ id 2 ║ name2 ║
  7. ╚═══════╩═══════════╝╚═══════╩═══════════╝
  8. ads:
  9. ╔════════════╦══════════════╗
  10. ║ creator_id ║ category_id ║
  11. ╠════════════╬══════════════╣
  12. ║ user.id1 ║ category.id1 ║
  13. ║ user.id2 ║ category.id2 ║
  14. ╚════════════╩══════════════╝
  15.  
  16. SELECT COUNT(DISTINCT users.id) AS count FROM users
  17. INNER JOIN ratings
  18. ON users.id = receiver_id
  19. LEFT JOIN ads
  20. ON users.id = ads.creator_id
  21. LEFT JOIN categories
  22. ON categories.id = ads.category_id
  23. WHERE user_type = "tutor"
  24. AND categories.name IN ("economy","anatomy")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement