Skip to content
Advertisement

How to deal with Dynamic Queries

Simple Question

I have a table that looks like this

enter image description here

I am looking to do is do a select so I can get a result as

enter image description here

Is this a PIVOTING issue? looking for suggestions to see how I can form a ‘Select’ query for this?

Advertisement

Answer

If you want to merge rows having the same values in the first three columns, then use aggregation:

select columna, columnb,columnc, max(columnd) columnd, max(columne) columne
from mytable
group by columna, columnb, columnc

Aggregate functions – such as max() – ignore null values, so max(columnd) gives you the non-null value across rows having the same (columna, columnb,columnc).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement