Results 1 to 2 of 2

Thread: How to write this SQL query?

  1. #1
    Join Date
    Nov 2003
    Posts
    3

    Question How to write this SQL query?

    CUSTOMER
    Name City IndustryType
    Abernathy Construction Willow B
    Amalgamated Housing Mernphis B
    Manchester Lumber Manchester F
    Tri-City Builders Memphis B

    ORDERS
    Number CustName SalespersonName Amount
    100 Abernathy Construction Zenith 560
    200 Abernathy Construction Jones 1800
    300 Manchester Lumber Abel 480
    400 Abernathy Construction Abel 2500
    500 Abernathy Construction Murphy 6000
    600 Tri-City Builders Abel 700
    700 Manchester Lumber Jones 150
    800 Abernathy Construction Abel 75000

    SALESPERSON
    Name PercentOfQuota Salary
    Abel 63 132000
    Baker 38 46200
    Jones 26 49500
    Kobad 27 39600
    Murphy 42 55000
    Zenith 59 129800

    I have got the three tables above.
    Would you help me to write a SQL query to show the names and PercentOfQuota of sales people who have an order with all cuatomers.
    Thank you very much!

  2. #2
    Join Date
    Dec 2003
    Posts
    1

    Lightbulb Re: Query

    Here you go:

    select spname, avg(quota)
    from orders inner join salesperson on orders.spname = salesperson.[name]
    group by spname having count (distinct(orders.custName)) = (select count(*) from customer)



    Maybe the field names do not match with yrs so change the field names accordingly.

    Regards,
    Deepak
    Last edited by deepaka; 12-03-2003 at 07:31 AM.

Posting Permissions

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