MySQL Query For Browser Version
up vote
2
down vote
favorite
I have a table in my MySQL database that stores login data, and I store the useragent header info, for example:
{"userAgent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"}
I am trying to query which browser and version people are using to access the site. This is the query I have so far:
SELECT
Browser,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
WHEN userAgent LIKE '%MSIE+%' THEN 'IE'
ELSE 'Unknown'
END AS Browser
FROM user_log
)
AS Browsers
GROUP BY Browser
My question is how can I add the browser version to this query?
mysql sql
add a comment |
up vote
2
down vote
favorite
I have a table in my MySQL database that stores login data, and I store the useragent header info, for example:
{"userAgent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"}
I am trying to query which browser and version people are using to access the site. This is the query I have so far:
SELECT
Browser,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
WHEN userAgent LIKE '%MSIE+%' THEN 'IE'
ELSE 'Unknown'
END AS Browser
FROM user_log
)
AS Browsers
GROUP BY Browser
My question is how can I add the browser version to this query?
mysql sql
You would add additional rows to thecase
expression.
– Gordon Linoff
Nov 8 at 11:51
This might be helpful, although the answer isn't promising: dba.stackexchange.com/questions/34724/…
– Henning Koehler
Nov 8 at 12:23
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a table in my MySQL database that stores login data, and I store the useragent header info, for example:
{"userAgent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"}
I am trying to query which browser and version people are using to access the site. This is the query I have so far:
SELECT
Browser,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
WHEN userAgent LIKE '%MSIE+%' THEN 'IE'
ELSE 'Unknown'
END AS Browser
FROM user_log
)
AS Browsers
GROUP BY Browser
My question is how can I add the browser version to this query?
mysql sql
I have a table in my MySQL database that stores login data, and I store the useragent header info, for example:
{"userAgent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"}
I am trying to query which browser and version people are using to access the site. This is the query I have so far:
SELECT
Browser,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
WHEN userAgent LIKE '%MSIE+%' THEN 'IE'
ELSE 'Unknown'
END AS Browser
FROM user_log
)
AS Browsers
GROUP BY Browser
My question is how can I add the browser version to this query?
mysql sql
mysql sql
asked Nov 8 at 11:13
Shaun
34018
34018
You would add additional rows to thecase
expression.
– Gordon Linoff
Nov 8 at 11:51
This might be helpful, although the answer isn't promising: dba.stackexchange.com/questions/34724/…
– Henning Koehler
Nov 8 at 12:23
add a comment |
You would add additional rows to thecase
expression.
– Gordon Linoff
Nov 8 at 11:51
This might be helpful, although the answer isn't promising: dba.stackexchange.com/questions/34724/…
– Henning Koehler
Nov 8 at 12:23
You would add additional rows to the
case
expression.– Gordon Linoff
Nov 8 at 11:51
You would add additional rows to the
case
expression.– Gordon Linoff
Nov 8 at 11:51
This might be helpful, although the answer isn't promising: dba.stackexchange.com/questions/34724/…
– Henning Koehler
Nov 8 at 12:23
This might be helpful, although the answer isn't promising: dba.stackexchange.com/questions/34724/…
– Henning Koehler
Nov 8 at 12:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
I managed to figure this out, I hope this is useful to someone in the future:
SELECT
Browser,
Version,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
ELSE 'Unknown'
END AS Browser,
CASE
WHEN userAgent LIKE '%Firefox%' THEN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9)) + 1)
WHEN userAgent LIKE '%Chrome%' THEN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8)) + 1)
WHEN userAgent LIKE '%MSIE %' THEN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5, POSITION('.' IN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5)) + 1)
ELSE 'Unknown'
END AS Version
FROM user_log
)
AS Browsers
GROUP BY Browser, Version
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I managed to figure this out, I hope this is useful to someone in the future:
SELECT
Browser,
Version,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
ELSE 'Unknown'
END AS Browser,
CASE
WHEN userAgent LIKE '%Firefox%' THEN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9)) + 1)
WHEN userAgent LIKE '%Chrome%' THEN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8)) + 1)
WHEN userAgent LIKE '%MSIE %' THEN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5, POSITION('.' IN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5)) + 1)
ELSE 'Unknown'
END AS Version
FROM user_log
)
AS Browsers
GROUP BY Browser, Version
add a comment |
up vote
1
down vote
I managed to figure this out, I hope this is useful to someone in the future:
SELECT
Browser,
Version,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
ELSE 'Unknown'
END AS Browser,
CASE
WHEN userAgent LIKE '%Firefox%' THEN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9)) + 1)
WHEN userAgent LIKE '%Chrome%' THEN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8)) + 1)
WHEN userAgent LIKE '%MSIE %' THEN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5, POSITION('.' IN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5)) + 1)
ELSE 'Unknown'
END AS Version
FROM user_log
)
AS Browsers
GROUP BY Browser, Version
add a comment |
up vote
1
down vote
up vote
1
down vote
I managed to figure this out, I hope this is useful to someone in the future:
SELECT
Browser,
Version,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
ELSE 'Unknown'
END AS Browser,
CASE
WHEN userAgent LIKE '%Firefox%' THEN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9)) + 1)
WHEN userAgent LIKE '%Chrome%' THEN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8)) + 1)
WHEN userAgent LIKE '%MSIE %' THEN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5, POSITION('.' IN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5)) + 1)
ELSE 'Unknown'
END AS Version
FROM user_log
)
AS Browsers
GROUP BY Browser, Version
I managed to figure this out, I hope this is useful to someone in the future:
SELECT
Browser,
Version,
COUNT(Browser) AS Count
FROM
(
SELECT
CASE
WHEN userAgent LIKE '%Firefox%' THEN 'Firefox'
WHEN userAgent LIKE '%Chrome%' THEN 'Chrome'
WHEN userAgent LIKE '%MSIE %' THEN 'IE'
ELSE 'Unknown'
END AS Browser,
CASE
WHEN userAgent LIKE '%Firefox%' THEN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Firefox', userAgent) + 9)) + 1)
WHEN userAgent LIKE '%Chrome%' THEN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8, POSITION('.' IN SUBSTRING(userAgent, LOCATE('Chrome', userAgent) + 8)) + 1)
WHEN userAgent LIKE '%MSIE %' THEN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5, POSITION('.' IN SUBSTRING(userAgent, LOCATE('MSIE ', userAgent) + 5)) + 1)
ELSE 'Unknown'
END AS Version
FROM user_log
)
AS Browsers
GROUP BY Browser, Version
answered Nov 8 at 18:20
Shaun
34018
34018
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206603%2fmysql-query-for-browser-version%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You would add additional rows to the
case
expression.– Gordon Linoff
Nov 8 at 11:51
This might be helpful, although the answer isn't promising: dba.stackexchange.com/questions/34724/…
– Henning Koehler
Nov 8 at 12:23