日期:2014-05-17 浏览次数:20696 次
--true
;with a1 (品名,单价,地域别) as
(
select 'a',10,1 union all
select 'a',11,2 union all
select 'b',5,1 union all
select 'b',4,2 union all
select 'c',3,1 union all
select 'd',6,2
)
,a2 as
(
select *,row_number() over(partition by 品名 order by 地域别) re from a1
)
select 品名,单价,地域别
from a2
where re=1
--False
;with a1 (品名,单价,地域别) as
(
select 'a',10,1 union all
select 'a',11,2 union all
select 'b',5,1 union all
select 'b',4,2 union all
select 'c',3,1 union all
select 'd',6,2
)
,a2 as
(
select *,row_number() over(partition by 品名 order by 地域别 desc) re from a1
)
select 品名,单价,地域别
from a2
where re=1
create table kc
(品名 varchar(5),单价 int,地域别 int)
insert into kc
select 'a',10,1 union all
&