[英]Pervasive SQL Update with top
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... 但是,它必须在Pervasive V10中工作。
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): 这是Pervasive的Update帮助(我在那里看不到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 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;
创建视图View1作为按dateField从aTable顺序中选择ID的视图;
Then use the view in the Update: 然后使用更新中的视图:
update aTable set aField = 'value' where aTable.Id in (select top 400 a.Id from View1 a );
更新aTable设置aField ='value'其中aTable.Id在(从View1a中选择顶部400 a.Id);
I've tested with PSQL v11 but it should also work with PSQL v10. 我已经对PSQL v11进行了测试,但它也应与PSQL v10一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.