SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculate same values [Problem]

    i need the MySQL query for calculate the number the rows that have a same value in a one or more cells:
    See my example:

    Code:
    -----------------------------------------
    # | user_ip | user_useragent | user_lang
    -----------------------------------------
    1 | 55.12.15 | Firefox        | en
    2 | 55.12.11 | Firefox        | en
    3 | 55.12.15 | IE             | en
    4 | 55.12.15 | Opera          | en
    5 | 55.12.15 | Firefox        | de
    6 | 55.12.15 | IE             | en
    7 | 55.12.81 | Firefox        | en
    -----------------------------------------
    Request : That calculate number of rows that have a same value in the `user_lang` and `user_useragent`:
    The rows 1, 2, 7 have same value in `user_lang` and `user_useragent`. >> 3 row
    Also the rows 3 and 6 have same value in `user_lang` and `user_useragent`. >> 2 row
    The result must be 5.
    Did you understand? I want the SQL comment to process for getting number 5.

    I can use the array_unique in PHP for calculate but i want process it with MySQL functions.
    thanks and be waiting.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT user_useragent
         , user_lang
         , COUNT(*) AS rows
      FROM daTable
    GROUP
        BY user_useragent
         , user_lang
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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