virtuexru Posted February 2, 2009 Share Posted February 2, 2009 Hey guys. Mondays suck. I've been asked to write a script to determine how many vehicles have been added by employees in the past WEEK. So basically, I would need a count on employees for who had the most vehicles posted in the past one week. My database is setup like this: Row Name: _author can contain any persons e-mail for example: "[email protected]" or "[email protected]". Row Name: _added is the DATE the person posted the vehicle in this format: YYYY-MM-DD. Now, how would I go about counting who had the most posts in the past week? Anyone have any ideas? I've tried a few things with mktime but alas, no avail. Here is my SQL for vehicle postings for ALL-TIME (not one week) just for reference: $count = "SELECT DISTINCT _author, COUNT(_author) AS count FROM dbname GROUP BY _author ORDER BY count DESC LIMIT 10"; Link to comment https://forums.phpfreaks.com/topic/143495-i-hate-dates-the-worst-is-adding-and-subtracting-them/ Share on other sites More sharing options...
corbin Posted February 2, 2009 Share Posted February 2, 2009 What is the data type of _added? Anyway, assuming it's varchar (ewww..... use date or something else), you could do this: SELECT _author, COUNT(*) as total_vehicles FROM table WHERE WEEKOFYEAR(DATE(_added)) = WEEKOFYEAR(NOW())-1 AND YEAR(DATE(_added)) = YEAR(NOW()); Question, by the way.... Do you want a week ago from the current day, or do you want a week as in Monday-Sunday (or Sunday - Saturday depending on how you look at it)? I'm hoping someone will have a better query... one that takes everything into account lol. If you want a week from the current day, that's easy though. Link to comment https://forums.phpfreaks.com/topic/143495-i-hate-dates-the-worst-is-adding-and-subtracting-them/#findComment-753008 Share on other sites More sharing options...
fenway Posted February 3, 2009 Share Posted February 3, 2009 You think mysql has poor date functionality? Seriously??? Try working with mssql. Link to comment https://forums.phpfreaks.com/topic/143495-i-hate-dates-the-worst-is-adding-and-subtracting-them/#findComment-753327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.