If you group by WEEK start_time, then this is what you should choose (instead of the date itself). Otherwise, how would you report bills? You want to show the counter every week, not every date.
You also have a semantic error in your where argument - you must use parentheses to explicitly set the priority order in your ANDs and ORs.
SELECT WEEK(start_time) AS Week, COUNT(1) AS Count FROM offline_execution_jobs WHERE start_time >= NOW() - INTERVAL 365 DAY AND (application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT' ) GROUP BY WEEK(start_time) ORDER BY WEEK(start_time) ASC ;
This request:
SELECT WEEK(start_time) AS Week, COUNT(1) AS Count FROM offline_execution_jobs WHERE start_time >= NOW() - INTERVAL 365 DAY AND (application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT' ) GROUP BY WEEK(start_time) ORDER BY WEEK(start_time) ASC ;
It returns the following result:
1 21 2 50 3 15
But I need something like this:
2011-01-04 08:05:24 21 2011-01-09 03:28:54 8 2011-01-16 06:08:18 11 2011-01-23 06:06:50 32
And when I execute this request from MySqlYog (Windows MySql client), I get the desired result, problems arise when I execute this request from php code:
SELECT start_time AS WEEK, COUNT(1) AS COUNT FROM offline_execution_jobs WHERE start_time >= NOW() - INTERVAL 365 DAY AND (application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT' ) GROUP BY WEEK(start_time) ORDER BY WEEK(start_time) ASC ;
Here is the error I get from php:
Invalid query: 'nolio_db.offline_execution_jobs.start_time' isn't in GROUP BY Whole query: SELECT start_time AS Date, COUNT(1) AS Count FROM offline_execution_jobs WHERE start_time >= NOW() - INTERVAL 250 DAY AND (application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT' ) GROUP BY WEEK(start_time) ORDER BY WEEK(start_time) ASC ;
And here is what it looks like in the code:
$query = "SELECT start_time AS Date, COUNT(1) AS Count FROM offline_execution_jobs WHERE start_time >= NOW() - INTERVAL 250 DAY AND (application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT' ) GROUP BY WEEK(start_time) ORDER BY WEEK(start_time) ASC ;"; //echo "<br><br>$query<br><br>"; // Create connection to DB $conn = mysql_connect($db_host, $db_user, $dp_pass); if (!$conn) { echo "<br/>Can't connect: $db_host"; die('Could not connect: ' . mysql_error()); }