Forum Moderators: open
i have been reading on Pivot Tables, INNER JOINS, SUM, CASE statements in regards to having multiple GROUP BY statements in my query string.
here is what i have currently:
$sql = 'SELECT nhm_associate, COUNT(nhm_associate) AS weekscount,(SELECT COUNT(*) FROM registration_table WHERE DATE_SUB(CURDATE(),INTERVAL 6 DAY) <= entry_time) AS totalcount FROM registration_table WHERE DATE_SUB(CURDATE(),INTERVAL 6 DAY) <= entry_time GROUP BY nhm_associate ORDER BY entry_time';
i also want to add this:
SELECT COUNT(*) FROM registration_table WHERE DATE_SUB(CURDATE(),INTERVAL 2 DAY) = entry_time AS yesterday GROUP BY nhm_associate
i would be tremendously grateful for any insight on how to combine these statements...
cant get this to work quite right, but i know i am close...
SELECT nhm_associate, COUNT(nhm_associate) WHERE DATE_SUB(CURDATE(),INTERVAL 6 DAY) <= entry_time AS weekscount,
SUM(CASE COUNT(*) WHERE DATE_SUB(CURDATE(),INTERVAL 6 DAY) <= entry_time THEN 1 END) AS totalcount,
SUM(CASE COUNT(*) WHERE DATE_SUB(CURDATE(),INTERVAL 2 DAY) = entry_time THEN 1 END) AS yesterday
FROM registration_table GROUP BY nhm_associate';