Extbase查询以比较同一表中的两个字段 [英] Extbase query to compare two fields in same table
问题描述
是否可以在查询api中比较两个数据库字段?例如,我想比较以下字段tstamp和crdate:
Is it possible to compare two database fields in the query api? For example I want compare the fields tstamp and crdate like:
SELECT * FROM tt_content WHERE tstamp > crdate;
在查询api中找不到解决方案.获取所有记录并在循环中比较字段不是一种执行的方法,因为这可能超过200万条记录(以我的实际情况而言).
In the query api I could not found a solution. To get all records and compare the fields in a loop is not a performed way, because this could be over 2 million records (in my real case).
感谢您的帮助.
推荐答案
我能想到的(并且查询构建器支持)的唯一方法是直接提供该语句.看起来像这样:
The only way I can think of (and that the query builder supports) is to directly supply the statement. It'll look like this:
$query = $contentElementRepository->createQuery();
$query->statement('SELECT * FROM tt_content WHERE tstamp > crdate');
$matchingContentElements = $query->execute();
这可能会破坏数据库抽象层,因此请谨慎使用. statement()
有第二个参数,您可以在其中放置参数,以防在查询中需要一些用户输入.
This probably breaks the database abstraction layer, so use it with caution. statement()
has a second parameter where you can put parameters, in case you need some user input in the query.
也许还有另一种我不知道的方法,我本人对此会真的很感兴趣.
Maybe there is another way to do this which I don't know, I'd be really interested in it myself.
这篇关于Extbase查询以比较同一表中的两个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!