Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    19

    Wink Unanswered: need help with sum in query

    heres the sql
    Code:
    SELECT FuelUsed.uDate, FuelUsed.[Equipment Number], FuelUsed.Gallons
    FROM FuelUsed INNER JOIN qryHrsDiff ON (FuelUsed.[Equipment Number] = qryHrsDiff.Expr1) AND (FuelUsed.[Equipment Number] = qryHrsDiff.Expr2)
    WHERE (((FuelUsed.uDate) Between [qryHrsDiff]![T1.readDate] And [qryHrsDiff]![T2.readDate]));
    it has 3 fields
    uDate
    Equipment Number
    Gallons

    i need to consoladate(sum) the gallons per equipment number. i cant get anything working. any ideas?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT f.[Equipment Number]
         , SUM(f.Gallons) AS total_gallons
      FROM FuelUsed AS f
    INNER 
      JOIN qryHrsDiff AS q
        ON ( 
           F.[Equipment Number] = qryHrsDiff.Expr1 
       AND F.[Equipment Number] = qryHrsDiff.Expr2
       AND F.uDate BETWEEN q.[T1.readDate] 
                       AND q.[T2.readDate]
           )
    GROUP
        BY f.[Equipment Number]
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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