<i id='U9S4i'><tr id='U9S4i'><dt id='U9S4i'><q id='U9S4i'><span id='U9S4i'><b id='U9S4i'><form id='U9S4i'><ins id='U9S4i'></ins><ul id='U9S4i'></ul><sub id='U9S4i'></sub></form><legend id='U9S4i'></legend><bdo id='U9S4i'><pre id='U9S4i'><center id='U9S4i'></center></pre></bdo></b><th id='U9S4i'></th></span></q></dt></tr></i><div id='U9S4i'><tfoot id='U9S4i'></tfoot><dl id='U9S4i'><fieldset id='U9S4i'></fieldset></dl></div>

<small id='U9S4i'></small><noframes id='U9S4i'>

        <bdo id='U9S4i'></bdo><ul id='U9S4i'></ul>
        <tfoot id='U9S4i'></tfoot><legend id='U9S4i'><style id='U9S4i'><dir id='U9S4i'><q id='U9S4i'></q></dir></style></legend>

      1. 如何在 Doctrine2 中使用 SQL 的 YEAR()、MONTH() 和 DAY()?

        How can I use SQL#39;s YEAR(), MONTH() and DAY() in Doctrine2?(如何在 Doctrine2 中使用 SQL 的 YEAR()、MONTH() 和 DAY()?)
      2. <small id='D9KCN'></small><noframes id='D9KCN'>

          <tbody id='D9KCN'></tbody>

          <tfoot id='D9KCN'></tfoot>
        1. <legend id='D9KCN'><style id='D9KCN'><dir id='D9KCN'><q id='D9KCN'></q></dir></style></legend>
          <i id='D9KCN'><tr id='D9KCN'><dt id='D9KCN'><q id='D9KCN'><span id='D9KCN'><b id='D9KCN'><form id='D9KCN'><ins id='D9KCN'></ins><ul id='D9KCN'></ul><sub id='D9KCN'></sub></form><legend id='D9KCN'></legend><bdo id='D9KCN'><pre id='D9KCN'><center id='D9KCN'></center></pre></bdo></b><th id='D9KCN'></th></span></q></dt></tr></i><div id='D9KCN'><tfoot id='D9KCN'></tfoot><dl id='D9KCN'><fieldset id='D9KCN'></fieldset></dl></div>

                • <bdo id='D9KCN'></bdo><ul id='D9KCN'></ul>

                  本文介绍了如何在 Doctrine2 中使用 SQL 的 YEAR()、MONTH() 和 DAY()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在本机 SQL 中执行如下所示的查询:

                  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) = 2013 AND
                      MONTH(t.timestamp) = 09 AND
                      DAY(t.timestamp) = 16 AND
                      t.somethingelse LIKE 'somethingelse'
                  GROUP BY
                      t.somethingelse;
                  

                  如果我想像这样在 Doctrine 的查询构建器中实现这个:

                  If I am trying to implement this in Doctrine's query builder like this:

                  $qb = $this->getDoctrine()->createQueryBuilder();
                  $qb->select('e.column AS average_value')
                     ->from('MyBundle:MyEntity', 'e')
                     ->where('YEAR(e.timestamp) = 2013')
                     ->andWhere('MONTH(e.timestamp) = 09')
                     ->andWhere('DAY(e.timestamp) = 16')
                     ->andWhere('u.somethingelse LIKE somethingelse')
                     ->groupBy('somethingelse');
                  

                  我收到错误异常

                  [语法错误] 第 0 行,第 63 列:错误:预期已知函数,得到 'YEAR'

                  [Syntax Error] line 0, col 63: Error: Expected known function, got 'YEAR'

                  如何使用 Doctrines 查询构建器实现我的查询?

                  How can I implement my query with Doctrines query builder?

                  注意事项:

                  • 我了解 Doctrine 的原生 SQL.我已经尝试过这个,但它导致了我的生产数据库表和我的开发数据库表具有不同名称的问题.我想在数据库不可知的情况下工作,所以没有选择.
                  • 虽然我想工作与数据库无关:仅供参考,我使用的是 MySQL.
                  • 有一种方法可以扩展 Doctrine 以学习"YEAR() 等语句,例如如见此处.但我正在寻找一种避免包含第三方插件的方法.
                  • I know about Doctrine's Native SQL. I've tried this, but it leads to the problem that my productive and my development database tables have different names. I want to work database agnostic, so this is no option.
                  • Although I want to work db agnostic: FYI, I am using MySQL.
                  • There is way to extend Doctrine to "learn" the YEAR() etc. statements, e.g. as seen here. But I am looking for a way to avoid including third party plugins.

                  推荐答案

                  你可以添加Doctrine extension 所以如果您使用的是 Symfony,则可以通过添加此配置来使用 MySql YEARMONTH 语句:

                  You can add Doctrine extension so you can use the MySql YEAR and MONTH statement by adding this configuration if you're on Symfony:

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

                  现在您可以在 DQL 或查询构建器中使用 MONTH 和 YEAR 语句.

                  now you can use the MONTH and YEAR statements in your DQL or querybuilder.

                  注意:扩展支持 MySQL、Oracle、PostgreSQL 和 SQLite.

                  Note: The extension supports MySQL, Oracle, PostgreSQL and SQLite.

                  这篇关于如何在 Doctrine2 中使用 SQL 的 YEAR()、MONTH() 和 DAY()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                • <i id='vtNFk'><tr id='vtNFk'><dt id='vtNFk'><q id='vtNFk'><span id='vtNFk'><b id='vtNFk'><form id='vtNFk'><ins id='vtNFk'></ins><ul id='vtNFk'></ul><sub id='vtNFk'></sub></form><legend id='vtNFk'></legend><bdo id='vtNFk'><pre id='vtNFk'><center id='vtNFk'></center></pre></bdo></b><th id='vtNFk'></th></span></q></dt></tr></i><div id='vtNFk'><tfoot id='vtNFk'></tfoot><dl id='vtNFk'><fieldset id='vtNFk'></fieldset></dl></div>

                    <tbody id='vtNFk'></tbody>

                  1. <tfoot id='vtNFk'></tfoot>

                        <small id='vtNFk'></small><noframes id='vtNFk'>

                        <legend id='vtNFk'><style id='vtNFk'><dir id='vtNFk'><q id='vtNFk'></q></dir></style></legend>
                        • <bdo id='vtNFk'></bdo><ul id='vtNFk'></ul>