15,967,051 members
See more:
Hi experts,

I have got this output by below mensioned query
IPS_Facility_Name                      percentage
abcefg Certficate                            28
PQRSTUV Certificate                      21
XYZABC Certificate                        16
xlmnopq Certificate                       9
Yojane cirtificate                            6
Others                                         20

Query
SQL
```Select top 5 IPS_Facility_Name,
from Intermediate_MonthWise_Statistics
--where IPS_Month =@month  and IPS_Year =@year
group by IPS_Facility_Name
having SUM(IPS_TotRaised)>0
order by SUM(IPS_TotRaised) desc```

I want to sum the percentage column and that will be subtracted from 100 this result i want to add as a new row that is 100-(Sum(PercentageColumn))=20

Plese help me to calculate others row in sql query

(Keerthi Kumar)
Posted
Varsha Ramnani 1-Apr-14 5:44am
you can use temptable to store the result of this query and then use sum(PercentageColumn) and Union

## Solution 2

http://sqlfiddle.com/#!3/6dfc5/11[^]

v2

## Solution 1

You can use TempTable as follows :

```DECLARE @TempTable TABLE
(
IPS_Facility_Name VARCHAR(100),
FacilityPercentage int
)

INSERT INTO @TempTable
( IPS_Facility_Name,FacilityPercentage )
Select top 5 IPS_Facility_Name,
from Intermediate_MonthWise_Statistics
--where IPS_Month =@month  and IPS_Year =@year
group by IPS_Facility_Name
having SUM(IPS_TotRaised)>0
order by SUM(IPS_TotRaised) DESC

INSERT INTO @TempTable
( IPS_Facility_Name,FacilityPercentage )
SELECT 'Total Percentage',100 - SUM(FacilityPercentage) FROM @TempTable

SELECT * FROM @TempTable```