Getting a total of a number of group by results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ZiggyShort
    New Member
    • Jan 2008
    • 6

    Getting a total of a number of group by results

    I need to summate across a number of line items over a group of invoices, then round down on an invoice by invoice basis to the nearest penny.
    I would then like to get a total of THOSE rounded values.
    Does my sql need to return the items, and i then manually summate these values by reading each one by one, or can I do this in the sql. Remember, I still need to round on an invoice by invoice basis.
    My sql which returns rounded invoice totals is given below:


    SELECT
    SUM(FLOOR(sii.u nitPrice*sii.Qt y)) AS total
    FROM salesinvoiceIte m sii,
    salesinvoice si
    WHERE sii.invoiceId = si.invoiceId
    GROUP BY si.InvoiceId

    ;

    This returns a number of rows which I then need a total for: is there an elegant way of achieving this in sql server in a query?
  • ZiggyShort
    New Member
    • Jan 2008
    • 6

    #2
    Sorted it:

    SELECT SUM(total)
    FROM
    (
    SELECT
    SUM(FLOOR(sii.u nitPrice*sii.Qt y)) AS total
    FROM salesinvoiceIte m sii,
    salesinvoice si
    WHERE sii.invoiceId = si.invoiceId
    GROUP BY si.InvoiceId )somename

    Comment

    Working...