Results 1 to 5 of 5

Thread: Aggregates

  1. #1
    Join Date
    Nov 2003
    Posts
    3

    Unanswered: Aggregates

    Hey all... I'm very new to SQL and in search of a good source of information. These forums seem to be perfect from what I've seen.

    Right now I'm in search of help on a problem. I have a table which lists sales (ID, Date, SaleAmt). From this table a View has been Created to sum all the sales for the ID (EmpID, Tot_Sales). What I'm trying to do is create a report to show the percentage of total sales each ID has. So it would be something like Tot_Sales/SUM(Tot_Sales), however, nothing I've tried thus far has worked. Can anybody please help with this?

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    What sql are you using (SQL Server, Oracle, Informix ...) ?

  3. #3
    Join Date
    Nov 2003
    Posts
    3
    It's out of a Microfocus product, and I believe its IBM DB2.

  4. #4
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Your Comment->
    "So it would be something like Tot_Sales/SUM(Tot_Sales), however, nothing I've tried thus far has worked"

    This is correct, except for 'GROUP BY x' where x is the/many columns projected in the select statement that are not aggregate functions.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  5. #5
    Join Date
    Nov 2003
    Posts
    3
    Thank you both for the help. I've found the problem in incorrect usage of the group by clause.

    Thanks

Posting Permissions

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