CGRRay Posted October 11, 2006 Share Posted October 11, 2006 I have a table full of members who have joined our organization over the past several years and continue to join and renew. Their membership lasts for a specific amount of time, usually 1 year or 6 months. I need to write a query that will tell me how many members there were at the end of each month by chapter, for each month of this year. All the records are stored in two tables called member and chapter. The fields in member are: member_id, first_name, last_name, date_joined, date_renewed, date_expires, chapter_id. The fields in chapters are: chapter_id, member_id, title.I tried using this: SELECT chapter.title,(SELECT COUNT(*)FROM memberWHERE member.chapter_id = chapter.chapter_idAND member.date_expires > 1138751999) AS membersFROM chapterORDER BY chapter.title; but then realized that I was counting all the people who joined or renewed after Jan 31 too.I sure would appreciate some help.Thanks Link to comment https://forums.phpfreaks.com/topic/23639-counting-records-by-date/ Share on other sites More sharing options...
fenway Posted October 11, 2006 Share Posted October 11, 2006 Why not use a BETWEEN clause? Link to comment https://forums.phpfreaks.com/topic/23639-counting-records-by-date/#findComment-107560 Share on other sites More sharing options...
CGRRay Posted October 13, 2006 Author Share Posted October 13, 2006 Thanks for responding. I found a different way to do this:SELECT chapter.title,(SELECT COUNT(*)FROM memberWHERE member.chapter_id = chapter.chapter_idAND member.date_expires > 1146441599) AS members_as_of_Mar31,(SELECT COUNT(*)FROM memberWHERE member.chapter_id = chapter.chapter_idAND member.date_expires BETWEEN 1146441600 AND 1162339199) AS expired_after_Mar31,(SELECT COUNT(*)FROM memberWHERE member.chapter_id = chapter.chapter_idAND member.date_joined BETWEEN 1146441600 AND 1162339199) AS joined_after_Mar31,(SELECT COUNT(*)FROM memberWHERE member.chapter_id = chapter.chapter_idAND member.date_renewed BETWEEN 1146441600 AND 1162339199) AS renewed_after_Mar31FROM chapterORDER BY chapter.title;The results in MySQL Query Browser look correct. The problem is that this query works in MySQL Query Browser but not in my live version of MySQL. I get this error:#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Any Ideas?Thnaks again Link to comment https://forums.phpfreaks.com/topic/23639-counting-records-by-date/#findComment-108427 Share on other sites More sharing options...
fenway Posted October 13, 2006 Share Posted October 13, 2006 Not really... that's a rather undescriptive error. Link to comment https://forums.phpfreaks.com/topic/23639-counting-records-by-date/#findComment-108558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.