使用MySQL生成自定义报告

时间:2016-03-17 17:56:32

标签: html mysql transactions

我正在设计一个需要生成报告的网站。报告必须生成详细交易,并按日交易分组总交易。数据表格式如下所示。



 _______________________________________

    |Name | Check in Date | Chec out Date | 
    ---------------------------------------
    |     |              |                |
    |     |              |                |
-------------------------------------------




我希望报告的格式如下表所示。



    _______________________________________

    |Name | Check in Date | Chec out Date | 
    ---------------------------------------
    |     |              |                |
    |     |              |                |
    _______________________________________

   | Total  for Day 1  |                  |
   ---------------------------------------   
    |     |              |                |
    |     |              |                |
    _______________________________________
   | Total  for Day 2  |                  |
   ---------------------------------------




当我运行下面的SQL查询时



SELECT check_in_time , chec_out_time , COUNT(check_in_time) FROM 
table_name GROUP BY check_in_time ORDER BY check_in_time DESC




然后我得到以下结果。



        _______________________________________________________________
   
        |Name | Check in Date | Chec out Date | COUNT(check in time)   |
        --------------------------------------------------------------
        |     |              |                |
        |     |              |                |    2                   |
        ________________________________________________________________

        |     |              |                |
        |     |              |                |       5                 |
        ________________________________________________________________

        |     |              |                |
        |     |              |                |            3          |
        ________________________________________________________________

      




我实际上希望每行中显示的每个事务和新行中的一天的总事务。

1 个答案:

答案 0 :(得分:0)

我使用mysql关键字ROLLUP来获得所需的结果。下面是sql脚本。



SELECT check_in_time , chec_out_time , COUNT(check_in_time) FROM 
table_name GROUP BY check_in_time DESC , id WITH ROLLUP;