Show sum in the last row

  • hello all,

    I have a table with some rows and columns what i want is i want to Show sum of particular column in the last row.

    this is my code.

    SELECT DISTINCT Cluster.ClusterName, Gruppe.GruppeName, Arbeitspaket.ArbeitspaketName, BMWProjekt, AnzahlAP, Abgerechnet, InBearbeitung, Billanz FROM Bestellung

    INNER JOIN Cluster ON Bestellung.Cluster = Cluster.rowid

    INNER JOIN Arbeitspaket ON Bestellung.Arbeitspaket = Arbeitspaket.rowid

    INNER JOIN Gruppe ON Bestellung.Gruppe = Gruppe.rowid

    WHERE Projekt ="EA-284-Nxx" AND AnzahlAP <> 0 AND Abgerechnet is 1 AND InBearbeitung is NULL AND Billanz is NULL;

  • How about a table create script or some sample data, more importantly You can lookup MSDN since what your asking for a very basic t-SQL.

    https://msdn.microsoft.com/en-us/library/ms177673.aspx

    Jayanth Kurup[/url]

  • I have a table with some rows and columns what i want is i want to Show sum of particular column in the last row.

    The last row of what? What client are you using?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Here is example you can make sum of column UserAge of table UserMaster as below and can do the same for as many column as you want.

    select cast(usercode as varchar(10)) usercode, UserAge

    from UserMaster

    union all

    select 'Total', sum(UserAge)

    from UserMaster

  • You can use WITH ROLLUP, GROUPING SETS or other GROUP BY options.

    More info: https://technet.microsoft.com/en-us/library/bb522495(v=sql.105).aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply