Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an employee table in which there is a column of salary name. Now I want the sum of the salary column in the last row but the total should be written in the row next to it as per the photo below where null is written.

select emp_name,SUM(emp_salary) as salary 
from   employe 
group by emp_name WITH ROLLUP 
order by emp_name desc

enter image description here

And the table format looks the same with the employee name


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use COALESCE:

coalesce(emp_name,'Total') as emp_name

In your query:

select coalesce(emp_name,'Total') as emp_name,
       SUM(emp_salary) as salary 
  from employe 
group by emp_name WITH ROLLUP 
order by emp_name desc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...