Guest User

Untitled

a guest
Jun 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. -- there's 5 events in the range 2010-10-15 to 2010-10-21
  2. -- event1,event2,event3 and event4 have start_at in 2010-10-20
  3. -- and event5 is on 2010-10-21
  4. -- thats their tags: event1{tag1,tag2,tag3,tag4}, event2{tag1,tag2,tag3}, event3{tag1,tag2}, event4{tag1}
  5. -- and event5 has only 'tag4'... so..
  6. -- the tag count in the range 2010-10-15 to 2010-10-21 should display count = 2 for tag4...but its ignoring
  7. -- the 2010-10-21 day, what is wrong with this select?
  8.  
  9. -- event with id = 13 is the one with tag4 with the start_at thats being ignored(2010-10-21)
  10. sqlite> select events.* from events where events.id = 13;
  11. id = 13
  12. name = event 5
  13. descricao =
  14. local_id = 6
  15. incluir_mapa =
  16. flyer_file_name =
  17. flyer_content_type =
  18. flyer_file_size =
  19. flyer_updated_at =
  20. start_at = 2010-10-21 02:00:00
  21. end_at = 2010-10-21 02:00:00
  22. created_at = 2010-10-22 00:08:09
  23. updated_at = 2010-10-22 00:08:09
  24. user_id = 7
  25.  
  26. -- this is the select I can't figure out whats wrong and the (wrong) result
  27. sqlite> SELECT tags.*, COUNT(*) AS count FROM "tags" LEFT OUTER JOIN taggings ON
  28. tags.id = taggings.tag_id AND taggings.context = 'tags' INNER JOIN events ON ev
  29. ents.id = taggings.taggable_id WHERE taggings.taggable_type = 'Event' AND events
  30. .start_at >= '2010-10-15' AND events.end_at <= '2010-10-21' GROUP BY tags.id, ta
  31. gs.name HAVING COUNT(*) > 0;
  32. id = 7
  33. name = tag1
  34. count = 4
  35.  
  36. id = 8
  37. name = tag2
  38. count = 3
  39.  
  40. id = 9
  41. name = tag3
  42. count = 2
  43.  
  44. id = 10
  45. name = tag4
  46. count = 1
Add Comment
Please, Sign In to add comment