一个关于内查询的问题,实在不明白
这是在本版看到的一个例子,但我有点不明。
表的结构如下:
create table price(p_productID int ,p_price int,p_userID int)
insert price select 1,500,10
union all select 1,1000,8
union all select 1,200,2
union all select 2,200,10
union all select 2,300,2
union all select 3,500,10
union all select 3,200,3
union all select 4,500,10
union all select 4,400,3
GO
查询语句如下:
Select * from price A
where A.p_price in( select MAX(p_price) from price B GROUP BY B.p_productID)
为什么结果会这样呢:
p_productID p_price p_userID
1 500 10
1 1000 2
3 500 10
4 500 10
而将p_productID为1,p_userID为10的p_price改为600时,结果却又变成这样:
p_productID p_price p_userID
1 1000 2
3 500 10
4 500 10
恳请赐教!