我只是创建一个SQL语句,并希望将它放在我的Typo3扩展中的有效查询构建器请求中。
SQL是
SELECT FROM_UNIXTIME(tx_operations_domain_model_operation.begin, '%Y') as year,
count(tx_operations_operation_type_mm.`uid_foreign`) as cont,
tx_operations_domain_model_type.`title`
FROM tx_operations_domain_model_operation
INNER JOIN
tx_operations_operation_type_mm ON (`tx_operations_operation_type_mm`.`uid_local` = tx_operations_domain_model_operation.uid)
INNER JOIN
tx_operations_domain_model_type ON (`tx_operations_domain_model_type`.`uid` = `tx_operations_operation_type_mm`.`uid_foreign`)
GROUP BY FROM_UNIXTIME(tx_operations_domain_model_operation.begin, '%Y'), tx_operations_operation_type_mm.`uid_foreign`;
这是我在控制器中尝试的内容
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_operations_domain_model_operation');
$statement = $queryBuilder
->select('tx_operations_domain_model_operation.begin, \'%Y\') as year', 'count(tx_operations_operation_type_mm.`uid_foreign`) as cont')
->from('tx_operations_domain_model_operation')
->join(
'tx_operations_domain_model_operation',
'tx_operations_operation_type_mm',
$queryBuilder->expr()->eq('tx_operations_operation_type_mm.uid_local', $queryBuilder->quoteIdentifier('tx_operations_domain_model_operation.uid'))
)
->join(
'tx_operations_operation_type_mm',
'tx_operations_domain_model_type',
$queryBuilder->expr()->eq('tx_operations_domain_model_type.uid_local', $queryBuilder->quoteIdentifier('tx_operations_operation_type_mm.uid_foreign'))
)
->groupBy('UNIXTIME(tx_operations_domain_model_operation.begin, \'%Y\')', 'tx_operations_operation_type_mm.`uid_foreign')
->execute();
任何想法查询构建器表示必须如何?
答案 0 :(得分:0)
我在实习期间一直在使用QueryBuilder,我认为你错过了一个别名:
->join(
'tt_content_orig',
'sys_language',
'sys_language', /** Insert alias name, in this case it's the same name **/
$queryBuilder->expr()->eq(
'tt_content_orig.sys_language_uid',
$queryBuilder->quoteIdentifier('sys_language.uid')
)
我一直在使用存储库文件。