简体   繁体   English

计数特定范围日期和时间的记录

[英]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. 我有一个数据库,该数据库存储在我们的在线系统上生成的可兑现凭单的详细信息,有四种特定的凭单类型,并且每次生成凭单时,它都会在数据库中存储DATETIME和凭单类型的记录。

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. 我可以生成一个.CSV文件,这是我认为的简单部分。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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