Results 1 to 4 of 4

Thread: help!

  1. #1
    Join Date
    Nov 2003
    Posts
    5

    Red face Unanswered: help!

    date company amount
    01/01 ABS 2000
    10/01 KB 1500
    02/03 ABS 4000
    02/04 LB 3000
    04/05 KB 3000
    05/06 LB 7000



    i need help to write a SQL statement which can output companies with a total amount over 5000 for the period 01/01 to 05/06.

  2. #2
    Join Date
    May 2004
    Location
    Barcelona, Spain
    Posts
    54
    try this

    select company, sum(amount)
    from table
    where (the conditions you like)
    group by company
    having sum(amount) > 5000

  3. #3
    Join Date
    Apr 2004
    Location
    Arizona
    Posts
    75

    Another way

    Select
    Company,
    Sum(Amount) as CompanyTotal

    From
    Table

    Where
    (CompanyTotal > 5000)
    AND
    ( Date > 01/01
    and
    Date < 05/06)

    Group by
    Company
    Last edited by AceOmega; 07-08-04 at 15:14.

  4. #4
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Please note that 'Having sum(amount) > x' is not equal to 'where amount > x'. Having is a post group function while where is a pre function.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

Posting Permissions

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