简体   繁体   中英

How to get a unique value in a row for different list of values?

This is the query I have written:

select c.id, CONCAT(c.major_version, '.', c.minor_version) as versions
from event_ids c
where c_id in ('101') group by c_id, major_version, minor_version;

This is the result I am getting

id versions
101 0.0
101 1.0
101 2.0
101 3.0

I am trying to get a single value against a list of different values for the same id.

id versions
101 0.0
1.0
2.0
3.0

How do I write the query so I get the desired result?

try this

select (case when rowNumber = 1 then c_id else null end) id, versions 
from (
    select ROW_NUMBER() OVER( PARTITION BY c.c_id ORDER BY major_version) as rowNumber, c.c_id, 
        CONCAT(c.major_version, '.', c.minor_version) as versions
    from event_ids c
    where c_id in ('101') group by c_id, major_version, minor_version
) tempTable

You could try

select case when c.major_version = 0 and c.minor_version = 0 then c.id else null 
end as id, 
CONCAT(c.major_version, '.', c.minor_version) as versions
from event_ids c
where c_id in ('101') group by c_id, major_version, minor_version;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM