简体   繁体   English

如何从PHP中的数据库每月和每年生成报告

[英]How to generate reports per month and per year from the database in php

I am creating a generation of reports per month and per year. 我每个月和每年创建一次报告。 There are 15 types of fees that I want to display the total sales per month. 我想显示每月总销售额的15种费用。 I have a date column in my database table with the format of (ex. 2014-09-27). 我的数据库表中有一个日期列,其格式为(例如2014-09-27)。 I don't know how to order by it per month (from Jan-Dec) then add all the total of each fee. 我不知道如何按月订购(从1月至12月),然后将所有费用的总和相加。 I have a drop down list to select the year so that I will display the reports per year and per month that depends to my selected year. 我有一个下拉列表来选择年份,这样我将显示取决于所选年份的每年和每月的报告。 Each fee in the database has a price. 数据库中的每个费用都有一个价格。

database name: Registration 数据库名称:注册

table name: Application 表名称:应用程序

columns: DATE_APPLICATION, Barangay_Business_Permit, Business_Plate, Sanitary_Inspection_Fee, Environmental_Clearance, Barangay_Development, Building_Permit, Electrical_Inspection, Mechanical_Inspection, Plumbing_Inspection, Health_Certificate, Signage_Fee, Penalty, Barangay_Clearance, Barangay_Certification, Construction_Clearance 列:DATE_APPLICATION,Barangay_Business_Permit,Business_Plate,Sanitary_Inspection_Fee,环境透明,Barangay_Development,Building_Permit,电气_检查,机械检查,水暖检查,健康_证书,标牌_费用,罚款,Barangay_Clearance,Barangay_Clearance,

Based on the updated information, You would need to pull a select based on the dates and then sum the columns grouping by the Date_Application if you want to calculate the totals for the applications by month or year. 根据更新的信息,如果要按月或年计算应用程序总数,则需要基于日期进行选择,然后对按Date_Application分组的列求和。 So for a monthly listing: 因此,对于每月列表:

Select SUM(Barangay_Business_Permit), SUM(Business_Plate), SUM(Sanitary_Inspection_Fee),
SUM(Environmental_Clearance), SUM(Barangay_Development), SUM(Building_Permit),
SUM(Electrical_Inspection), SUM(Mechanical_Inspection), SUM(Plumbing_Inspection),
SUM(Health_Certificate), SUM(Signage_Fee), SUM(Penalty), SUM(Barangay_Clearance),
SUM(Barangay_Certification), SUM(Construction_Clearance)
from Registration.application GROUP BY MONTH(DATE_APPLICATION);

For a yearly listing: 对于年度列表:

Select SUM(Barangay_Business_Permit), SUM(Business_Plate), SUM(Sanitary_Inspection_Fee),
SUM(Environmental_Clearance), SUM(Barangay_Development), SUM(Building_Permit),
SUM(Electrical_Inspection), SUM(Mechanical_Inspection), SUM(Plumbing_Inspection),
SUM(Health_Certificate), SUM(Signage_Fee), SUM(Penalty), SUM(Barangay_Clearance),
SUM(Barangay_Certification), SUM(Construction_Clearance)
from Registration.application GROUP BY YEAR(DATE_APPLICATION);

If you want to use the names for the months you would use MONTHNAME(DATE_APPLICATION) instead. 如果要使用月份的名称,则应改用MONTHNAME(DATE_APPLICATION)

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

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