Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/171830-browser-statistics-from-mysql/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.