【发布时间】:2021-03-10 12:05:55
【问题描述】:
我正在尝试使用 Typo3 中的 QueryInterface 添加订单,但我不知道如何将我的 mysql 查询转换为 Typo3 查询。
这是我的 mysql 查询:
SELECT * FROM `primary_table` pt
ORDER BY (
IFNULL(
(select SUM(a.score) from child_table_1 a
left join child_table_1_mm b on a.uid = b.uid_foreign
where b.uid_local = pt.uid and a.uid = 3), 0) +
IFNULL(
(select SUM(a.score) from child_table_2 a
left join child_table_2_mm b on a.uid = b.uid_foreign
where b.uid_local = pt.uid and a.uid = 2), 0) +
IFNULL(
(select SUM(a.score) from child_table_3 a
where a.uid = pt.child_table_3_uid and a.uid = 0), 0))
desc;
所以基本上,我有一个主表,我想订购该表的结果,但要根据每个相关表的分数相加。在我的例子中,child_table_1 和 child_table_2 与主表的关系是 1:n,而 child_table_3 是 1:1。
我已经有一个使用 QueryInterface 的订单.. 类似
$query->setOrderings(array('pt.firstname'=>QueryInterface:ORDER_ASCENDING));
我尝试直接复制粘贴我的 mysql-order-by-version,甚至尝试只使用一个孩子以使事情变得更容易,即使没有 IFNULL,但我总是遇到错误“属性的 ColumnMap”SUM(a “...”类的“”丢失。
我尝试在 php 中而不是直接在 mysql 中排序,但结果有限,因此我的排序无法正常工作,因为我没有所有结果。
我可以写类似的东西
$query->setOrderings(array('pt.child_table_1.score'=>QueryInterface:ORDER_DESCENDING));
但我无法在其中添加SUM,既不是uid = 3 的条件,也不是为每个孩子添加分数的可能性。
结果出库时需要排序。我不知道是否可以使用 TCA 配置文件完成某些操作。我在映射字段时看到了诸如 foreign_table 之类的属性,但我不知道如何在我的情况下使其工作。
如何通过 Typo3 的逻辑使用这个 mysql 顺序?
【问题讨论】:
标签: mysql typo3 typo3-7.6.x queryinterface