Tuesday, April 6, 2010

Just a MySQL statement I need to remember

select count(distinct userName) from userTracking where timeStamp >= '2010-03-30' AND status LIKE '%Logged into $%';

counts unique userNames from userTracking between March 30th 2010 and now and looks for "Logged into $" in the status field.

and even better:

SELECT COUNT(DISTINCT userName) FROM userTracking WHERE timeStamp >= DATE(NOW()) - INTERVAL 11 DAY + INTERVAL 10 HOUR AND timeStamp <= DATE(NOW()) - INTERVAL 0 DAY + INTERVAL 10 HOUR AND status LIKE '%Logged into $%';

between 11 days ago at 10am and today at 10am.

No comments:

Post a Comment