declare @t table
(名称 varchar(5),时间 datetime,期限 varchar(20),公司 varchar(20),价格 decimal(10,3))insert @t
select 'aaaa','2006-02-07','十二个月','AAA印刷厂',1000.0000 union all
select '中国','2006-02-07','六个月','BBB印刷厂',800.0000 union all
select 'aa','2006-02-07','三个月','CCC印刷厂',1500.0000 union all
select '中国','2006-02-07','三个月','DDD印刷厂',500.0000
select * from @t a
where not exists (select * from @t b where a.名称=b.名称 and a.价格<b.价格)
order by 名称,价格 desc名称 时间 期限 公司 价格
----- ------------------------------------------------------ -------------------- -------------------- ------------
aa 2006-02-07 00:00:00.000 三个月 CCC印刷厂 1500.000
aaaa 2006-02-07 00:00:00.000 十二个月 AAA印刷厂 1000.000
中国 2006-02-07 00:00:00.000 六个月 BBB印刷厂 800.000(所影响的行数为 3 行)
(名称 varchar(5),时间 datetime,期限 varchar(20),公司 varchar(20),价格 decimal(10,3))insert @t
select 'aaaa','2006-02-07','十二个月','AAA印刷厂',1000.0000 union all
select '中国','2006-02-07','六个月','BBB印刷厂',800.0000 union all
select 'aa','2006-02-07','三个月','CCC印刷厂',1500.0000 union all
select '中国','2006-02-07','三个月','DDD印刷厂',500.0000
select * from @t a
where not exists (select * from @t b where a.名称=b.名称 and a.价格<b.价格)
order by 名称,价格 desc名称 时间 期限 公司 价格
----- ------------------------------------------------------ -------------------- -------------------- ------------
aa 2006-02-07 00:00:00.000 三个月 CCC印刷厂 1500.000
aaaa 2006-02-07 00:00:00.000 十二个月 AAA印刷厂 1000.000
中国 2006-02-07 00:00:00.000 六个月 BBB印刷厂 800.000(所影响的行数为 3 行)
(名称 varchar(5),时间 datetime,期限 varchar(20),公司 varchar(20),价格 decimal(10,3))insert @t
select 'aaaa','2006-02-07','十二个月','AAA印刷厂',1000.0000 union all
select '中国','2006-02-07','六个月','BBB印刷厂',800.0000 union all
select 'aa','2006-02-07','三个月','CCC印刷厂',1500.0000 union all
select '中国','2006-02-07','三个月','DDD印刷厂',500.0000
select * from @t T
where 价格=(select max(价格) from @t where 名称=T.名称)
order by 名称
(名称 varchar(5),时间 datetime,期限 varchar(20),公司 varchar(20),价格 decimal(10,3))insert @t
select 'aaaa','2006-02-07','十二个月','AAA印刷厂',1000.0000 union all
select '中国','2006-02-07','六个月','BBB印刷厂',800.0000 union all
select 'aa','2006-02-07','三个月','CCC印刷厂',1500.0000 union all
select '中国','2006-02-07','三个月','DDD印刷厂',500.0000
select 名称,max(时间) as 时间,max(期限) as 期限,max(公司) as 公司,max(价格) as 价格
From @t group by 名称 order by max(价格) desc
select 名称,max(时间) as 时间,max(期限) as 期限,max(公司) as 公司,max(价格) as 价格
From @t group by 名称 order by max(价格) desc写法二
select * from @t T where 价格=(select max(价格) from @t where 名称=T.名称)
order by 名称都可以 但是第二种写法性能上应该好些