Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,979
    Thanks
    120
    Thanked 76 Times in 76 Posts

    Shrink table data

    sample data:

    Code:
    text                      count
    foo?l2=en               3 
    foo                        4 
    foo?p1=x&l2=de       1
    foo?p1=x&l2=en       1
    foo?p1=x                1
    need to shrink this into

    Code:
    text                      count
    foo                        7
    foo?p1=x                3
    Need to cut out all 'l2=xx' from URL-and sumarize count.

    Smart ideas needed, using MYSQL only of course.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,525
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    The best I could do, I think, would be to cut off all the parts of each URL that begin with the ampersand (&).

    Something like this:

    Code:
    SELECT CASE WHEN url LIKE '%&%'
                THEN LEFT(url, INSTR(url, '&')-1)
                ELSE url END AS surl,
           SUM( `count` ) AS totalcount
    FROM table
    GROUP BY surl
    Could of course also eliminate just '&l2=' but if the full URL is something like
    foo?p1=x&l2=de&bug=17233
    then the "bug=" will be removed.

    Hmmm...if you ALWAYS wanted to removed "&l2=xx" where the only part that varies is "xx" then I have another better answer.
    Last edited by Old Pedant; 07-10-2014 at 09:39 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,979
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Quote Originally Posted by Old Pedant View Post

    Hmmm...if you ALWAYS wanted to removed "&l2=xx" where the only part that varies is "xx" then I have another better answer.
    nope. "&l2=xx" or "?l2=xx"

    I'm thinkinmg to get lib_mysqludf_preg

    if instaling is as easy as this : #15 Installing on Windows - lib_mysqludf_preg - mysqludf


    Add two files & run install sql ?

    Doh I'm not sure if perl regex notation is what I like.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,525
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Regular expressions of any kind would be tons simpler than what I'm thinking of doing. Try them first?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •