SUM of only TOP 10 rows

后端 未结 2 1570
暖寄归人
暖寄归人 2021-02-14 00:59

I have a query where I am only selecting the TOP 10 rows, but I have a SUM function in there that is still taking the sum of all the rows (disregarding the TOP 10). How do I get

相关标签:
2条回答
  • 2021-02-14 01:26

    Use the TOP feature with a nested query

    SELECT SUM(innerTable.Purchase_Total_Amount) FROM
    (SELECT TOP 10 Purchase_Total_Amount FROM Table) as innerTable
    
    0 讨论(0)
  • 2021-02-14 01:40

    Have you tried to use something like this:

    SELECT SUM(Whatever)
    FROM (
        SELECT TOP(10) Whatever
        FROM TableName
    ) AS T
    
    0 讨论(0)
提交回复
热议问题