MySQL: Grouping date by quarterly and half yearly

Hello

I am looking for some mysql query assistance from you experts :slight_smile:

I have a table that stores all the download logs of software on my website.

The table structure is as below:


CREATE TABLE `software_downloads` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `software_id` INT(10) DEFAULT NULL,
  `download_date` DATETIME DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=latin1

So what I am looking for is, when I generate reports, my customers should be able to group the dates by quarterly and half yearly. That means, if they choose the quarterly option, the report should list all the count of software download logs and group them by three months and six months in case if they choose the half-yearly option.

Thanks in advance for your help.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_quarter

For the half year results you could sum the relative quarter results in your PHP script (or whatever server side language you use).

Hi

I have One more query.

Please consider the following DDL


CREATE TABLE `software_downloads` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `software_id` INT(10) DEFAULT NULL,
  `download_by` VARCHAR(10) NOT NULL,
  `download_date` DATETIME DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=latin1

Here I added a new field “download_by”, The values for this column will either be “admin” or “customer”. so will it be possible to find out how many of the downloads are made by admin and how many of them are made by customers withing the same query?

Thanks

yeah, use GROUP BY download_by

Thank you very much for your kind help.