CREATE TABLE position
(
id BIGINT NOT NULL
,remark CHARACTER VARYING(255)
,uid CHARACTER VARYING(255)
,version INTEGER
,weight CHARACTER VARYING(255)
,CONSTRAINT position_pkey PRIMARY KEY (id)
) 其中每添加一条数据生成一个uid
,"version" initialize = 1;
每修改一条数据
,uid不变
,version + 1;
我需要相同的UID的查询,版本号的最大数据。
这是我的SQL:
select *
from position as c
where c.id in (select max (d.id) from position as d group by d.uid);
但它返回错误的数据。
select *
from position as c
where c.version in (select max (d.version)
from position as d
group by d.uid);
为什么此查询返回不同的结果?
[我如何问一个**好**问题?](http://stackoverflow.com/help/how-to-ask) –