oracle - Grouping SQL query to hard code column -


i have columns , date in dd/mm/yyyy format.

 date          description.    id.       amt 01/01/2000.       abc.       d1.     100  02/01/2000.       xyz.       r1      100 01/01/2000.       pqr.       d1.     100 01/02/2000.       cdf.       d1.     150 

now need query display

date          description.    id.      amt 01/01/2000.       abc.       d1.    200 02/01/2000.       xyz.       r1     100 01/02/2000.       cdf.       d1.    150 

i need group date , sum amount. need hard code description value abc of choice.

you can use case aggregation hardcode description when group size more 1 row.:

select the_date,     id,     case          when count(*) > 1             'abc'         else max(description)         end description,     sum(amt) amt your_table group the_date,     id 

also, note called date column the_date date reserved keyword. so, avoid using or escape using double quotes (i'd use other name).


Comments