我目前有以下结果:
ID Location
1 NYC
1 LA
2 NYC
3 PIT
我想要以下内容:
ID Location
1 Multiple
2 NYC
3 PIT
有谁知道一个简单的方法来实现这一目标?
答案 0 :(得分:1)
使用case
与count
和distinct
进行此处是一种方法:
select distinct id,
case when count(location) over (partition by id ) > 1
then 'Multiple' else location end Location
from yourtable
答案 1 :(得分:0)
使用sub-query
,COUNT
,CASE
,GROUP BY
:
SELECT mm.id, CASE WHEN mm.count > 1 THEN 'Multiple' ELSE loc END As Location
FROM
(SELECT COUNT(id) As count, id, MAX(location) As loc
FROM myTable
GROUP BY id) As mm;
答案 2 :(得分:0)
select ID,case when MIN(name) = MAX(name) then MIN(name) else 'multiple' end as Location
from <your tabel name>
group by id