schilly Posted August 25, 2009 Share Posted August 25, 2009 If I have a table that logs users with their browser info, what's the easiest command to be able to sort this info based on operating system? Can you use LIKE in a GROUP BY command? ex. SELECT count(id) as hits, operating_system FROM log GROUP BY operating_system LIKE "Windows" Would I have to use multiple queries for each OS (Mac, Windows, Mobile, etc) or can this by done in one query? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/171830-browser-statistics-from-mysql/ Share on other sites More sharing options...
kickstart Posted August 25, 2009 Share Posted August 25, 2009 Hi Don't think you could do that. You could probably use a case statement to create a pseudo column that contains the operating system SELECT id, (CASE WHEN operating_system LIKE "%Windows%" THEN "Bills System" WHEN operating_system LIKE "%Mac%" THEN "Steves System" ELSE "Another System") AS operating_system FROM log You could then use that as a subselect in a select to do the counts. SELECT operating_system, COUNT(id) FROM (SELECT id, (CASE WHEN operating_system LIKE "%Windows%" THEN "Bills System" WHEN operating_system LIKE "%Mac%" THEN "Steves System" ELSE "Another System") AS operating_system FROM log) Deriv1 GROUP BY operating_system All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/171830-browser-statistics-from-mysql/#findComment-906086 Share on other sites More sharing options...
schilly Posted August 25, 2009 Author Share Posted August 25, 2009 Thanks Keith. I'll give it a try. GROUP BY operating_system LIKE "%Macintosh%" works but it seems like you would have to do a query for each OS you wanted as each time it returns 2 rows(LIKE and NOT LIKE) Quote Link to comment https://forums.phpfreaks.com/topic/171830-browser-statistics-from-mysql/#findComment-906130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.