[英]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 的不同值列表获取单个值。
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.