select A,B,frequency,timekey
from (select t.*
,row_number() over(partition by A order by cast((B = 'unknown') as int), B) as rnum
from tbl t
) t
where rnum = 1
select A, B, Frequency, timekey
from
(select
A, B, Frequency, timekey,
row_number() over(partition by A,Frequency order by case when B='unknown' then 1 else 0 end) rn
)s where rn=1
如果你想选择 unknown 如果它们存在,就用这个 row_number 在上面的查询中:
row_number() over(partition by A,Frequency order by case when B='unknown' then 0 else 1 end) rn
2条答案
按热度按时间izj3ouym1#
这些条件可以使用
case
中的表达式order by
函数如下row_number
.在这里,对于每一组行,我们对除
B = 'unknown'
先是,然后是B
价值观。zdwk9cvp2#
使用
row_number
解析函数。如果要选择“不”unknown
先录制,然后使用以下查询:如果你想选择
unknown
如果它们存在,就用这个row_number
在上面的查询中: