本文介绍了集团采用月,年在教义2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在doctrine2中编写以下SQL查询作为DQL。

  c  c  c 

按月(日期时间格式Ymd H:i:s):

  SELECT p,SUBSTRING月份6,2)作为月
FROM实体p
GROUP BY月


How to write a following SQL query in doctrine2 as DQL .

SELECT COUNT(id)
FROM stats
WHERE YEAR(record_date) = 2009
GROUP BY YEAR(record_date), MONTH(record_date)

i.e i would like to group by results based on month,year of datetime field stored in MySQL table.

解决方案

In DQL you could also group by month, year, day etc with SUBSTRING.

For example - group by month (datetime format Y-m-d H:i:s):

SELECT p, SUBSTRING(p.date, 6, 2) as month
FROM Entity p
GROUP BY month

这篇关于集团采用月,年在教义2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:22
查看更多