简体   繁体   中英

Counting records for particular ranges dates and times

I have a database that stores details of money-off vouchers generated on our online system, there are four specific voucher types, and each time a voucher is generated, it stores a record in the database with a DATETIME and the voucher type.

I have to create a very specific spreadsheet report for a client that accepts two dates as ranges (so they say "generate a report between these two dates"), and then goes through EVERY DAY between those two ranges, and reports how many vouchers of that type were generated per to the closest hour. So a sample left hand column would look like this:

 27/7/2010 07:00
 27/7/2010 08:00
 27/7/2010 09:00
 27/7/2010 10:00

if there are no vouchers generated during a certain hour, it isn't shown on the spreadsheet.

Basically, i need some help figuring out how to generate this! i can generate a .CSV file, that's the simple part in my opinion. Apart from that, i don't have a clue where to begin.

 SELECT DATE_FORMAT(YourDateColumn, '%d/%M/%Y %H'), Count(Vouchers)
 FROM Table
 WHERE YourDateColumn between StartDate and EndDate 
 GROUP BY DATE_FORMAT(YourDateColumn, '%d/%M/%Y %H')
 ORDER By 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM