Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006
    Posts
    25

    Unanswered: Returning SUM and other columns in same query

    I'm wondering if there is a way to get something like this in one query:

    SELECT SUM(price) as totalPrice, SKU, description, price FROM salesItems WHERE SKU = 12243

    Thanks,

    Michael

  2. #2
    Join Date
    Sep 2006
    Posts
    25
    Doing something like this, gives me only one line... rather than all the sales for SKU 12243 and then a total...

    SELECT SUM(price) as totalPrice, SKU, description, price FROM salesItems WHERE SKU = 12243 GROUP BY SKU

    Any suggestions?

    Thanks,

    Michael
    Last edited by mvreade; 04-21-08 at 22:22.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT SKU
         , description
         , price 
      FROM salesItems 
     WHERE SKU = 12243 
    UNION ALL
    SELECT SKU
         , 'Total'
         , SUM(price)
      FROM salesItems 
     WHERE SKU = 12243 
    GROUP 
        BY SKU
    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
  •