按月份和年份在MySQL中 [英] Group by month and year in MySQL
本文介绍了按月份和年份在MySQL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定每行的时间戳记表,你将如何格式化查询以适应这个特定的json对象格式。
我正在组织一个json
json以查询为基础:
{
2009:[八月,七月,九月],
2010:[一月,二月,十月]
}
以下是到目前为止的查询 -
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
b b b b b b b b b b b b b b b b b b b b b b GROUP BY MONTH(t.summaryDateTime)DESC;
查询正在崩溃,因为它是(可预测的) )
解决方案
GROUP BY YEAR(t.summaryDateTime) MONTH(t.summaryDateTime)DESC;
是你想要的。
Given a table with a timestamp on each row, how would you format the query to fit into this specific json object format.
I am trying to organize a json object into years / months.
json to base the query off:
{
"2009":["August","July","September"],
"2010":["January", "February", "October"]
}
Here is the query I have so far -
SELECT
MONTHNAME(t.summaryDateTime) as month, YEAR(t.summaryDateTime) as year
FROM
trading_summary t
GROUP BY MONTH(t.summaryDateTime) DESC";
The query is breaking down because it is (predictably) lumping together the different years.
解决方案
GROUP BY YEAR(t.summaryDateTime), MONTH(t.summaryDateTime) DESC;
is what you want.
这篇关于按月份和年份在MySQL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文