简体   繁体   中英

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. I have a date column in my database table with the format of (ex. 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. 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

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. 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.

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