Fastest Web Hosting

group by month and year in mysql

0 votes
asked Sep 3, 2016 in Mysql by rohit (2,750 points)

i given table with a timestamp on each row, which are query used to fit into this specific json object format.

I want to organize a json object into years / months.but ima failled.
i am using this code.there something fault .
Help me

json based query off

{
  "2000":["june","July","August"],
  "2016":["January", "February", "December"]
}

query is here
i am using this query.

 SELECT
        MONTHNAME(summaryDateTime) as month, YEAR(t.summaryDateTime) as year
    FROM
        trading_summary t 
    GROUP BY EXTRACT(YEAR_MONTH FROM summaryDateTime) DESC";

1 Answer

0 votes
answered Sep 7, 2016 by Hein Htet Aung (260 points)

You can use like this

//daily
SELECT 
	MONTHNAME(summaryDateTime) as month, YEAR(t.summaryDateTime) as year
FROM trading_summary t 
	GROUP BY summaryDateTime
		
//monthly		
SELECT 
	MONTHNAME(summaryDateTime) as month, YEAR(t.summaryDateTime) as year
FROM trading_summary t 
	GROUP BY MONTH(summaryDateTime)

//yearly	
SELECT 
	MONTHNAME(summaryDateTime) as month, YEAR(t.summaryDateTime) as year
FROM trading_summary t 
	GROUP BY YEAR(summaryDateTime)

Job Board

TechnicalSharp is a technical community of developers where they are sharing their knowledge and solutions and against it they are getting the score point which help them to make profile strong which is under eyes on MNC's
...