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?










share|improve this question






















  • 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















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?










share|improve this question






















  • 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













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 11:13









Shaun

34018




34018












  • 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


















  • 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
















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












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





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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





    share|improve this answer

























      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





      share|improve this answer























        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





        share|improve this answer












        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 18:20









        Shaun

        34018




        34018






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff