我已经尝试过搜索功能,最合适的结果是这个,似乎对我的情况不起作用(?!):
[sql, keep only max value and delete others
我有一张这样的桌子
parentassembly | "Index" | partumber
----------------- ------------ -------------
pA 1| _00| part1
pa 1| _00| part2
pa 1|_ab| part1
pa 1|_ab| part3
pa 1|_af| part1
pa 1|_af| part2
pa 1|_af| part3
pa 1|_af| part4
pa 2| |part12
pa 2|| part...
pa 2|....| .....
我只需要具有最高索引的父装配和后续零件。
索引可以是数字或字母数字或空。
如果我尝试使用链接中所示的方法,但是进行了计数,那么我不会得到与所有表行相同的数字
select count(*)
(...or delete r....)
from pa_save r left join
(select parentassembly, Max("Index") as maxindex
from pa_save
group by parentassembly
) rn
on r.ParentAssembly = rn.ParentAssembly = rn.maxindex
where rn.ParentAssembly is null;
我已经尝试过使用子查询,也没有归档其他结果...
delete from pa_save
where parentassembly not in
(select parentassembly from pa_save where "Index" =
(select MAX("Index") from pa_save as pa_save2
where pa_save2.parentassembly = pa_save.parentassembly));
除了似乎无法正常工作之外,子查询还需要无尽的时间。...
任何见识将不胜感激。
亲切的问候,
Tobias
答案 0 :(得分:0)
您的第一个查询具有多个语法异常。这是您想要的吗?
select r.*
from pa_save r join
(select parentassembly, Max("Index") as maxindex
from pa_save
group by parentassembly
) rn
on r.ParentAssembly = rn.ParentAssembly and
r."Index" = rn.maxindex;