我目前有以下结果:
ID Location
1 NYC
1 LA
2 NYC
3 PIT
我想要以下内容:
ID Location
1 Multiple
2 NYC
3 PIT
有谁知道一个简单的方法来完成这个?
我目前有以下结果:
ID Location
1 NYC
1 LA
2 NYC
3 PIT
我想要以下内容:
ID Location
1 Multiple
2 NYC
3 PIT
有谁知道一个简单的方法来完成这个?
这是使用 and 的case
一种count
方法distinct
:
select distinct id,
case when count(location) over (partition by id ) > 1
then 'Multiple' else location end Location
from yourtable
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;
select ID,case when MIN(name) = MAX(name) then MIN(name) else 'multiple' end as Location
from <your tabel name>
group by id