如何在 extbase 中构建 maximumquery
how to build maximumquery in extbase
参考该文档 https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/3-implement-individual-database-queries.html 我想构建一个 maxquery 以从 table.
的记录中获取最高总和
点赞:
name | job | department | salary
john | salesmen | sales | 2000
max | mechanic | workshop | 1600
nicky | secretair | assistence | 1800
AS 输出:
John with an salary of 2000 earns the most.
如何将值从高到低排序并仅获取第一行?
在 Doctrine (v8+) 和存储库中,您仍然可以进行简单的查询,例如(存储库示例):
$query = $this->createQuery();
//here you can use max as well
$query->statement(
'
SELECT * FROM tx_sjroffers_domain_model_offer
WHERE title LIKE ? AND organization IN ?', array('%climbing%', array(33,47))
'
);
//true give us a raw result back otherwise we get objects
$res = $query->execute(true);
除了Xippo的回答,我还注意到以下几点:
使用$query->statement()
会导致 Extbase 不返回正确的结果计数。我在这里找到了解决这个问题的方法:
https://gist.github.com/smichaelsen/2bfdfb872d04a0776f01
参考该文档 https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/3-implement-individual-database-queries.html 我想构建一个 maxquery 以从 table.
的记录中获取最高总和点赞:
name | job | department | salary
john | salesmen | sales | 2000
max | mechanic | workshop | 1600
nicky | secretair | assistence | 1800
AS 输出:
John with an salary of 2000 earns the most.
如何将值从高到低排序并仅获取第一行?
在 Doctrine (v8+) 和存储库中,您仍然可以进行简单的查询,例如(存储库示例):
$query = $this->createQuery();
//here you can use max as well
$query->statement(
'
SELECT * FROM tx_sjroffers_domain_model_offer
WHERE title LIKE ? AND organization IN ?', array('%climbing%', array(33,47))
'
);
//true give us a raw result back otherwise we get objects
$res = $query->execute(true);
除了Xippo的回答,我还注意到以下几点:
使用$query->statement()
会导致 Extbase 不返回正确的结果计数。我在这里找到了解决这个问题的方法:
https://gist.github.com/smichaelsen/2bfdfb872d04a0776f01