1

我目前有以下结果:

ID    Location
1     NYC
1     LA
2     NYC
3     PIT

我想要以下内容:

ID    Location
1     Multiple
2     NYC
3     PIT

有谁知道一个简单的方法来完成这个?

4

3 回答 3

1

这是使用 and 的case一种count方法distinct

select distinct id, 
  case when count(location) over (partition by id ) > 1 
    then 'Multiple' else location end Location
from yourtable
于 2013-10-07T23:41:09.543 回答
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;

SQL小提琴

于 2013-10-08T00:56:54.610 回答
0
select ID,case when MIN(name) = MAX(name) then  MIN(name) else 'multiple' end as Location
from <your tabel name>
group by id
于 2013-10-08T03:24:31.433 回答