Click here to Skip to main content
15,914,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
query below gives me output of Designation , COunt , total , here total is sum of count , but total value 30 should be a at the end last row , please suggest, I am using the cte expr ,


with cte
as
(
select cm.cm_value as 'Designation', count(im.ticket_no) as 'Count'
from im_ticketmaster im
inner join user_master um on im.caller = um.userid
inner join common_master cm on um.Designation=cm.cm_id
group by cm.cm_value )
, cte2 as
(
select sum(count) Total from cte
)
select * from cte,cte2


Actual Output below


Designation Count Total
......................................
Account Executive 4 30
Account Manager 2 30
Accountant 2 30
Accounting 16 30
AP/PR Services 5 30
Assistant Director 1 30


Required output

Designation Count
......................................
Account Executive 4
Account Manager 2
Accountant 2
Accounting 16
AP/PR Services 5
Assistant Director 1
TOTAL 30
Posted

1 solution

try with union
SQL
SELECT  Designation, Count
FROM    cte
UNION
SELECT  'Total' as Designation, Total as Count
FROM    cte2;
 
Share this answer
 
Comments
Member 11579200 3-Apr-15 23:34pm    
Thank you . SImple .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900