oracle - How to concatenate "similar" rows in SQL? -


now have following sql:

select * (         select employee, template, trunc(a.from) date_from, sum(b.amounttotal) amnt_total, sum(b.amount) amnt     table1 a, table2 b, table3 c     ...     group employee, template, trunc(a.from)     )     pivot     (     sum (amnt_total)       date_from in ('01-may-2015' date1, '02-may-2015' date2, '03-may-2015' date3)     )  

and query result is:

+------------+------------+--------+---------+---------+---------+ |  employee  |  template  |  amnt  |  date1  |  date2  |  date3  | +------------+------------+--------+---------+---------+---------+ | kate       | templa     |    2   |         |    12   |         | | kate       | templa     |    4   |         |         |         | | kate       | templa     |    7   |    16   |         |    14   | | john       | templb     |    5   |    18   |    25   |         | +------------+------------+--------+---------+---------+---------+ 

how transform data following form:

+------------+------------+---------+---------+---------+ |  employee  |  template  |  date1  |  date2  |  date3  | +------------+------------+---------+---------+---------+ | kate       | templa     |   16|7  |   12|2  |   14|7  | | john       | templb     |   18|5  |   25|5  |         | +------------+------------+---------+---------+---------+ 

i know can use concatenation operator: add outer query:

select    employee,    template,    case when date1 not null date1||'|'||amnt end date0,   ...    (old_query) 

but how group?

you can use max non null value:

select    employee,    template,    max (date1||'|'||amt) date1,   ...    (old_query)   group employee, template 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -