Loading ...
Sorry, an error occurred while loading the content.

Re: [SQLQueriesNoCode] sum() on key id

Expand Messages
  • Noman Aftab
    PriceOfOrder should be in the Order table. Your schema is not normalized. Anyway, here is your query: SELECT ISNULL(SUM(amount), 0) FROM (SELECT
    Message 1 of 25 , Mar 11 9:32 AM
    • 0 Attachment
      PriceOfOrder should be in the Order table. Your schema is not normalized. Anyway, here is your query:

      SELECT ISNULL(SUM(amount), 0)
      FROM (SELECT DISTINCT id, amount
      FROM Table1
      WHERE (id = 1)) derivedTable

      base on assumption that for every record where OrderId is 1, the amount is the same.

      another solution based on same assumption:

      SELECT ISNULL(SUM(amount), 0)
      FROM (SELECT TOP 1 id, amount
      FROM Table1
      WHERE (id = 1)) derivedTable

      O S <owaiz_vaiyani@...> wrote:

      Hi
      I like to know how to do something like this

      table:
      orderid, orderitemid, stockid, priceOfOrder

      1 1 1 200
      1 2 2 200
      3 4 4 300


      then how can i do a sum on priceOfOrder
      it gives me 400 rather then 200 for order "1".

      thanks.


      __________________________________________________________
      Get Hotmail on your mobile, text MSN to 63463!
      http://mobile.uk.msn.com/pc/mail.aspx

      [Non-text portions of this message have been removed]






      ---------------------------------
      Rise to the challenge for Sport Relief with Yahoo! for Good

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.