Jump to content

MySQL: Grouping date by quarterly and half yearly

- - - - -

  • Please log in to reply
5 replies to this topic

#1
cancer10

cancer10

    Newbie

  • Members
  • PipPip
  • 20 posts
Hello

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


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.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
There are a couple ways you can do this:
1) issue requests for the aggregate data on a date range by date range basis
2) request all the data sorted by date and let your reporting tool handle adding summary data breaks at the appropriate point.
3) if you don't really care about the data, you could add an additional column for the quarter/half-year and use that for a group by clause.

The best choice will depend on the details of what's going on with your report.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
cancer10

cancer10

    Newbie

  • Members
  • PipPip
  • 20 posts
I actually want the date to group by Jan-Mar, Apr-Jun, July-Sep, Oct-Dec.

Please help me with the query

#4
cancer10

cancer10

    Newbie

  • Members
  • PipPip
  • 20 posts
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

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
select count(*), download_by from software_downloads group by download_by
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
cancer10

cancer10

    Newbie

  • Members
  • PipPip
  • 20 posts
Thank you very much for your kind help.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users