How can I use SQL's YEAR(), MONTH() and DAY() in Doctrine2?

后端 未结 5 1212
Happy的楠姐
Happy的楠姐 2020-11-29 07:04

I want to perform a query which would look like this in native SQL:

SELECT
    AVG(t.column) AS average_value
FROM
    table t
WHERE
    YEAR(t.timestamp) =          


        
5条回答
  •  鱼传尺愫
    2020-11-29 07:45

    In Symfony 4 you must install DoctrineExtensions:

    composer require beberlei/DoctrineExtensions
    

    And then edit the doctrine config file (config/packages/doctrine.yaml) as follow:

    doctrine:
        orm:
            dql:
                string_functions:
                    MONTH: DoctrineExtensions\Query\Mysql\Month
                    YEAR: DoctrineExtensions\Query\Mysql\Year
    

提交回复
热议问题