带有 top 的普遍 SQL 更新

发布于 2024-10-11 09:00:48 字数 1202 浏览 7 评论 0原文

我希望这样做:

update aTable 
set aField = 'value' 
where aTable.Id in (select top 400 Id from aTable order by dateField) .
-- This will run, but it only updates the first id it gets to in the IN clause

或这样:

update top 400 aTable set aField = 'value' order by dateField 
-- This will not run

但是,它必须在 Pervasive 的 V10 中工作...

类似的解决方法也足够了!

背景,我试图用按日期字段排序的值更新(项目的数量(可变))的字段。

这是 Pervasive 的更新帮助(我没有在那里看到 TOP 保留字):

UPDATE < table-name | view-name > [ alias-name ]

SET column-name = < NULL | DEFAULT
 | expression | subquery-
expression > [ , column-name = ... ] 
 [ FROM table-reference [, table-reference ] ...
 [ WHERE search-condition ]

table-name ::= user-defined-name 
 view-name ::= user-defined-name 
 alias-name ::= user-defined-name (Alias-name is not allowed if a 
FROM clause is used. See FROM Clause .)

 table-reference ::= { OJ outer-join-definition }

| [db-name.]table-name [ [ AS ] alias-name ]
 | [db-name.]view-name [ [ AS ] alias-name ]
 | join-definition | ( join-definition )
 | ( table-subquery )[ AS ] alias-name [ (column-name [ , column-name 
]... ) ]

I am looking to do this:

update aTable 
set aField = 'value' 
where aTable.Id in (select top 400 Id from aTable order by dateField) .
-- This will run, but it only updates the first id it gets to in the IN clause

or this:

update top 400 aTable set aField = 'value' order by dateField 
-- This will not run

But, it has to work in V10 of Pervasive...

A similiar workaround would be sufficient too!

Background, I am trying to update a (number(which is variable) of items)'s field with a value ordered by a date field.

Here is Pervasive's Update help (I do not see the TOP reserved word in there):

UPDATE < table-name | view-name > [ alias-name ]

SET column-name = < NULL | DEFAULT
 | expression | subquery-
expression > [ , column-name = ... ] 
 [ FROM table-reference [, table-reference ] ...
 [ WHERE search-condition ]

table-name ::= user-defined-name 
 view-name ::= user-defined-name 
 alias-name ::= user-defined-name (Alias-name is not allowed if a 
FROM clause is used. See FROM Clause .)

 table-reference ::= { OJ outer-join-definition }

| [db-name.]table-name [ [ AS ] alias-name ]
 | [db-name.]view-name [ [ AS ] alias-name ]
 | join-definition | ( join-definition )
 | ( table-subquery )[ AS ] alias-name [ (column-name [ , column-name 
]... ) ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2024-10-18 09:00:48

我做了一些测试,实现此功能的最佳方法是创建一个视图:

创建视图 View1 作为选择 ID
aTable 按日期字段排序;

然后使用Update中的视图:

更新 aTable 设置 aField = 'value'
其中aTable.Id in(选择前400个
a.View1 的 ID a);

我已经使用 PSQL v11 进行了测试,但它也应该适用于 PSQL v10。

I did some testing and the best way to get this working is to create a view:

create view View1 as select Id from
aTable order by dateField;

Then use the view in the Update:

update aTable set aField = 'value'
where aTable.Id in (select top 400
a.Id from View1 a );

I've tested with PSQL v11 but it should also work with PSQL v10.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文