日期:2014-05-17 浏览次数:20539 次
;
WITH huang
AS ( SELECT ROW_NUMBER() OVER ( PARTITION BY dealerid ORDER BY productid ) pid ,
productid ,
dealerid ,
pic ,
productname
FROM product
)
SELECT *
FROM huang
WHERE pid = 1
use tempdb
go
if object_id('#') is not null drop table #
create table #(productid int primary key,dealerid int,pic nvarchar(200),productname nvarchar(50))
insert into #(productid,dealerid,pic,productname) values
(1,1,'url1','a'),(2,1,'url2','b'),(3,2,'url3','c')
-- sql:
select * from # a where a.productid=(select max(productid) from # where dealerid=a.dealerid)
select * from # a where a.productid=(select min(productid) from # where dealerid=a.dealerid)