我有这个声明用于在表格中找到最大值(日期)。
SELECT *
from (
select
max(TIME) over (partition by artnumber) as "maxTIME",
artnumber,
TIME
from ADE_SPOCK_REP_PRIS
)
where TIME not like "maxTIME"
order by artnumber desc
如何在此声明前设置删除?
Delete from art where artnumber in
(SELECT *
from (
select
max(TIME) over (partition by artnumber) as "maxTIME",
artnumber,
TIME
from art
)
where TIME not like "maxTIME"
order by artnumber desc)
这不起作用。 你有什么提示吗?
答案 0 :(得分:0)
您问题的具体答案是修复子查询中的select *
:
Delete from art
where artnumber in (select artnumber
from (select max(TIME) over (partition by artnumber) as "maxTIME",
artnumber, TIME
from art
)
where TIME not like "maxTIME"
);
其他一些评论:
order by
通常没有意义。like
与日期和时间数据类型一起使用(需要使用本地化设置将值转换为字符串)。artnumber
都有最长时间。我怀疑这是你的意图。答案 1 :(得分:0)
尝试使用此查询
DELETE FROM art WHERE MAX(time) IN
(SELECT MAX(time) from art
GROUP BY MAX(time))
WHERE TIME NOT LIKE "%maxTIME%" GROUP BY MAX(time);