lundi 4 juillet 2016

Group by day but one result set for hours less than 16:00 and one for hours higher than 16:00

I'm stuck again! I got the following query to select a result set of customers and some dates. SELECT COUNT( DISTINCT CASE `saved` WHEN 0 THEN `cust` ELSE NULL END ) AS test, COUNT( DISTINCT CASE `saved` WHEN 1 THEN `cust` ELSE NULL END ) AS test2, DATE( `date` ) AS dateday FROM `salg_test` WHERE `is_void` = 0 GROUP BY dateday ORDER BY dateday DESC This can be seen as a total. Now I would like to separate this query based on the following condition: hour is less than 16:00 or more than 16:00. Im using PHPmyadmin, the date field is current_timestamp format, 24H clock. The problem is that i still need it to be grouped on DATE and not current_timestamp. If Possible I would like to excend my SQL query rather than using PHP, though i am echo'ing the query in to a table with a while loop. Any tips? Thanks so much for your help!

Aucun commentaire:

Enregistrer un commentaire