日期:2014-05-17 浏览次数:20526 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-05-09 21:34:48
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
-- Jun 17 2011 00:57:23
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[sellers]
if object_id('[sellers]') is not null drop table [sellers]
go
create table [sellers]([id] int,[seller] varchar(6),[product] varchar(14),[keyword] varchar(4),[price] numeric(2,1))
insert [sellers]
select 1,'沃尔玛','泰国稻米得大米','大米',6 union all
select 2,'沃尔玛','东北小麦粉','麦',3 union all
select 3,'百佳','东北大米','大米',3 union all
select 4,'家乐福','东北大米','大米',3.2 union all
select 5,'好又多','超级小麦面粉','麦',3.5 union all
select 6,'永辉','湖北大米','米',2.8
--------------开始查询--------------------------
SELECT *
FROM [sellers] a
WHERE EXISTS(SELECT 1 FROM (
select [keyword],MIN([price])[price]
from [sellers]
GROUP BY [keyword])&nbs