我每月和每年创建一代报告。我想要显示每月总销售额的15种费用。我的数据库表中有一个日期列,格式为(例如2014-09-27)。我不知道如何按月订购(从1月到12月),然后加上每笔费用的总额。我有一个下拉列表来选择年份,这样我就会显示每年和每月的报告,这些报告取决于我选择的年份。数据库中的每笔费用都有价格。
数据库名称:注册
表名:应用
列: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
答案 0 :(得分:0)
根据更新的信息,如果要按月或年计算应用程序的总计,则需要根据日期提取选择,然后将Date_Application的列分组相加。所以每月上市:
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);
每年上市:
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);
如果您想使用月份名称,请改用MONTHNAME(DATE_APPLICATION)
。