34,590
社区成员
发帖
与我相关
我的任务
分享
--进来了就参与一下
select *
from tb t
where icount=(select min(icount)
from tb
where NAME=t.NAME and city=t.city)
select ID,name,city,icount from tb a where not exists(select 1 from tb where a.name=name and a.city=city a.icount>icount)
--2 row_number() over是2005 新增的分析函数 很好
select ID,name,city,icount
from
(select ID,name,city,icount,
row_number() over(partition by name,city order by icount) rk
from tb) a
where a.rn=1
select id,name,city,icount from (
select *, row_number() over (partition by name,city order by icount) rn from tab) t
where rn=1
select * from tb t
where not exists (
select 1 from tb where t.name=name and t.city=city and t.icount>icount
)
select * from tb t
where (select count(*) from tb where NAME=t.NAME and CITYCITY=t.CITYCITY and t.icount<icount)<1