mySQL count occurrences with JOIN (with date parameters) -
i asked question here: mysql count occurrences join
this question, asked how count occurrences of tag after joining etc.
i'd know how this, checking event publish_date
want include tags within past 6 months or year.
**events** | id | publish_date | +-------------------------+ + 1 | 1377612000 | + 2 | 1377612000 | + 3 | 1377612000 | **event_categories** (stores tags / categories) | id | name | +-----------------+ + 1 | sport | + 2 | charity | + 3 | other_tag | **events_categories** (linking table) | event_id | event_category_id | +-------------------------------+ + 1 | 1 | + 2 | 2 | + 3 | 1 | + 3 | 2 |
sql returns count of tags (not taking account publish dates)select c.name
tag_name, count(ec.event_id) occurrences event_categories c inner join events_categories ec on c.id = ec.event_category_id group c.id
thanks! :)
select c.name tag_name, count(ec.event_id) occurrences event_categories c inner join events_categories ec on c.id = ec.event_category_id join events e on e.id = ec.event_id where(e.publish_end_date > (unix_timestamp() -7889229) or e.publish_end_date = 0) group c.id
Comments
Post a Comment