SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict ruba's Avatar
    Join Date
    Apr 2005
    Location
    Amman -Jordan
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question very complex query (is it possible)

    Hi every body ,

    I want to ask you if this case is possible, and how can I do it

    I have 2 tables the

    Customer
    id, city, and user_name,......


    services
    id, user_name, Service_name

    each customer have only one service ( relation is one to one )

    how can I get this result:
    Service_name, Count of customers that have this service for each city

    service name --count of users whom using this service in all cities-- city name--count of users whom using this service in each city

    example of the result
    service name -- total of user -- city1 -- city 2 -- city 3
    washing -- 20 --10 -- 3 -- 7
    cleaning -- 12 --3 -- 2 -- 7
    Open Blocked website
    Open Blocked Website
    Knowledge Is Knowing That A Tomato Is A Fruit,
    Wisdom Is Not Putting It In A Fruit Salad.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT s.service_name
         , c.city
         , COUNT(*) as customers
      FROM services AS s
    INNER
      JOIN customer AS c
        ON c.user_name = s.user_name
    GROUP
        BY s.service_name
         , c.city
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict ruba's Avatar
    Join Date
    Apr 2005
    Location
    Amman -Jordan
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Amazing ..
    thank u thank u thank u thaaaaaaaaaaaaaaaaaank u
    Open Blocked website
    Open Blocked Website
    Knowledge Is Knowing That A Tomato Is A Fruit,
    Wisdom Is Not Putting It In A Fruit Salad.


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
  •