按月分组查询结果

use*_*648 0 coldfusion coldfusion-9

我有一个coldfusion查询结果,它只包含日期

喜欢

2015-07-14 00:00:00.0   
2015-07-22 00:00:00.0   
2015-07-24 00:00:00.0   
2015-07-27 00:00:00.0   
2015-08-04 00:00:00.0   
2015-08-05 00:00:00.0   
2015-08-15 00:00:00.0   
2015-09-01 00:00:00.0   
2015-09-02 00:00:00.0   
2015-09-21 00:00:00.0   
2015-10-14 00:00:00.0   
2015-12-10 00:00:00.0   
2016-01-13 00:00:00.0 
Run Code Online (Sandbox Code Playgroud)

我想显示基于月份对它们进行分组的查询结果

例如,作为第一列的月份名称,然后是每行的月份日期.我不知道如何在这种情况下对查询进行分组.

Mat*_*che 5

更新您的查询以获得a yearmonth列.你不指定DMBS但对于MSSQL你可以使用year(),month()day()功能.确保您的查询按年,月和日排序,否则分组将无法正常工作.ColdFusion还有一个内置函数,monthAsString()用于将整数转换为月份名称.

SELECT year(datecolumn) AS Year, month(datecolumn) AS month, day(datecolumn) AS day, other, columns
FROM mytable
WHERE x = y
ORDER BY year, month, day
Run Code Online (Sandbox Code Playgroud)

输出为

<cfoutput query="myquery" group="year">
  <cfoupt group="month">
    #monthAsString(month)#
    <cfoutput group="day">
      #day# #other# #columns#
    </cfoutput>
  </cfoutput>
</cfoutput>
Run Code Online (Sandbox Code Playgroud)