且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果存在另一个记录,则排除该记录的值

更新时间:2023-02-21 23:03:49

select 
  id, 
  case 
     when count(case mark when 'C' then 1 else null end) = 0 
     then 
        sum(amount)
     else 
        sum(case when mark <> 'A' then amount else 0 end)
  end
from sampletable
group by id