2

In PL/SQL developer I want to write a query which gives merged rows value for a column? ex. if emp 1 and 2 has same salary like 200 and employee 3,4,5 has a salary of 1000 then the out put should be like for 1 and 2 emp the result should show single value 200 merging two rows. for emp 3,4 and 5 the salary column should show only single value 1000 merging 3 rows in salary column.

like shown in image

enter image description here

Puja Loni
  • 21
  • 1
  • 1
    This might help you: https://stackoverflow.com/questions/1076011/how-can-multiple-rows-be-concatenated-into-one-in-oracle-without-creating-a-stor – Abi Divi Oct 12 '17 at 07:07
  • Please read http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557 and the accepted answer –  Oct 12 '17 at 07:58

2 Answers2

0

In order to group by AND sum AND show the value you could use:

create table vls(empid int, tval int);
insert into vls(empid, tval)
    values (1,200),(2,200),(3,1000),(4,1000),(5,1000);
select tval as grouped_value,sum(tval) as sum_tval,avg(tval) as avg_tval
from vls
group by tval;
Jon Scott
  • 4,144
  • 17
  • 29
0
create table vls(empid int, tval int);

insert into vls(empid, tval) values (1,200);
insert into vls(empid, tval) values (2,200);
insert into vls(empid, tval) values (3,1000);
insert into vls(empid, tval) values (4,1000);
insert into vls(empid, tval) values (5,1000);

select listagg(empid, ' ') within group (order by empid) as empids, tval
from vls
group by
 tval;
user1
  • 556
  • 2
  • 6
  • 22