0
I have the following SQL structure:
CREATE TABLE IF NOT EXISTS `noticia` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_categoria` int(11) DEFAULT NULL,
`titulo` varchar(255) NOT NULL,
`previa` text NOT NULL,
`descricao` text,
`imagem` varchar(255) NOT NULL DEFAULT '',
`data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`views` int(11) DEFAULT '0',
`youtube` varchar(255) DEFAULT NULL,
`ativo` tinyint(4) NOT NULL,
PRIMARY KEY (`id`,`ativo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I would like to elaborate an SQL that query the records, grouping month and year. that appears as follows:
- How can I group MONTH/YEAR to assemble this listing? To display, I develop normal, my doubt is only in SQL.
I thought I’d make:
SELECT * FROM noticia GROUP BY MONTH(data);
If I do so, I will group only by month, and if I have the same month next year, I will group as well. And that is not the intention. I thank you!
Using mysql? There is a better way to do this.
– gmsantos