开发者

SQL Mangement Studio/SQL: Seeing the GroupBy / Sum aggregate functions

Quite new to this but i have created a SQL script that groups by and Sums a column.. but in SQL Management studio it shows me a grid with column value but nothing underneath it i.e. the SUM..

Do i have to configure SQL Management studio to show me the SUM or something..

Here is my query its very easy

    SELECT  RowNum ,
    ClientName ,
    ( SELECT    SUM(Amount) AS Expr1
    ) AS Amount
    FROM    #TempItems
    GROUP BY RowNum , Amount , ClientName

I also changed it to display TextView rather than GRIDVIEW but still no hope.

It displays the 开发者_JAVA百科Amount column correctly but i don't see any SUM underneath it

Any help really appreciated


You don't need the subselect:

SELECT
    RowNum ,
    ClientName ,
    SUM(Amount) AS Amount
FROM #TempItems
GROUP BY RowNum, ClientName


Just happened onto this post... The answer is to Martin's question is - WITH ROLLUP:

SELECT
    RowNum ,
    ClientName ,
    SUM(Amount) AS Amount
FROM #TempItems
GROUP BY RowNum, ClientName WITH ROLLUP

You'll get extra rows with NULL in the group by column for the subtotals, total.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜