SUM with GROUP BY with doctrine

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_pxcdownloads_domain_model_merkzettel');
$queryBuilder->select('file_reference_uid')
    ->addSelectLiteral(
        $queryBuilder->expr()->sum('tx_pxcdownloads_domain_model_merkzettel.stats_downloads', 'downloads')
    )
    ->from('tx_pxcdownloads_domain_model_merkzettel')
    ->groupBy('tx_pxcdownloads_domain_model_merkzettel.file_reference_uid')
    ->orderBy('count', 'desc')
    ->execute()->fetchAll();

Be the first to comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.