#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Help :( group by multiple values in single column


    group by multiple values in single column

    I have 3 different columns and I want to sort each value in percentage like 100% to 1%
    e.g. suppose 3 columns are country, visited cities, travelled by

    i.e. suppose country is India, cities are mumbai, kolkata, chennai and travelled by bus, train, plane

    So we have ids into the database separated by comma for cities and travelled by,
    Now we have to sort maximum number of people first giving priority to country then travelled by and then visited cities and put them in ascending order
    So please suggest me can we do with single MySQL query or we need to go for any searching and grouping algorithm.
    We are seeking all to be done with minimum coding efforts, I tried all possible ways but coding approach was heavy, seeking non robust database tables and effective search query or algorithm.

    Thanks in advance
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,205
    Rep Power
    4279
    sounds like you have a mess on your hands -- "we have ids into the database separated by comma"

    please do a SHOW CREATE TABLE for the table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0
    Actually we have 3 separate tables- country,cities and travelled by
    in one table(user) we are adding these with 3 different fields
    The user table is have columns - name. country, visited cities, travelled by
    and a single row have values like "Mahesh", "1", "25,32,7","17,7,12"

    Where country: 1-India
    cities: 25-mumbai, 32-kolkata, 7-chennai
    and travelled by: 17-bus, 7-train, 12-plane
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,928
    Rep Power
    378
    Yes. See normalization.
  8. #5
  9. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,205
    Rep Power
    4279
    Originally Posted by MaheshCL
    and a single row have values like "Mahesh", "1", "25,32,7","17,7,12"
    this needs to be normalized
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0
    How can I apply percentage logic on this normalized form of query, I am thinking about keeping normalized data in an array. Shall I completely depend on programming or I can fetch percentage wise data via sql query
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,928
    Rep Power
    378
    eh?
  14. #8
  15. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,205
    Rep Power
    4279
    Originally Posted by MaheshCL
    How can I apply percentage logic on this normalized form of query, I am thinking about keeping normalized data in an array.
    you keep using that word "normalized"

    i do not think it means what you think it means

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo