从数据库中检索数据作为报告

时间:2017-02-21 09:10:21

标签: postgresql

我想以报告的形式从数据库中检索数据,所以我有不同季度(4个季度)的收入类型。来自的数据类似于:

96;"9";500.00;"2016-05-03";"Tribal levy";"DAVHANA";"QUARTER ONE";2
98;"0/9";1000.00;"2016-05-19";"Customary Fee";"DAVHANA";"QUARTER ONE";2
99;"0/10";700.00;"2016-05-22";"Fine";"DAVHANA";"QUARTER ONE";2
100;"0/91";1200.00;"2016-05-24";"Tribal levy";"DAVHANA";"QUARTER ONE";2
101;"0/92";900.00;"2016-06-07";"Tribal levy";"DAVHANA";"QUARTER ONE";2
102;"1/21";600.00;"2016-08-16";"Customary Fee";"DAVHANA";"QUARTER TWO";2
105;"0/94";500.00;"2016-06-21";"Fine";"DAVHANA";"QUARTER ONE";2
106;"0/95";800.00;"2016-06-21";"Tribal levy";"DAVHANA";"QUARTER ONE";2
107;"1/25";500.00;"2016-07-13";"Fine";"DAVHANA";"QUARTER TWO";2
108;"1/66";200.00;"2016-08-23";"Fine";"DAVHANA";"QUARTER TWO";2
109;"1/67";300.00;"2016-09-28";"Fine";"DAVHANA";"QUARTER TWO";2
110;"011";2000.00;"2016-10-03";"Tribal levy";"DAVHANA";"QUARTER THREE";2
111;"012";1500.00;"2016-10-25";"Customary Fee";"DAVHANA";"QUARTER THREE";2
115;"017";1200.00;"2016-12-26";"Customary Fee";"DAVHANA";"QUARTER THREE";2
116;"444";200.00;"2017-01-25";"Tribal levy";"DAVHANA";"QUARTER FOUR";2
118;"099";800.00;"2017-02-22";"Tribal levy";"DAVHANA";"QUARTER FOUR";2
120;"67";500.00;"2017-03-14";"Tribal levy";"DAVHANA";"QUARTER FOUR";2
123;"32";500.00;"2017-01-24";"Fine";"DAVHANA";"QUARTER FOUR";2

QRY:

SELECT income.income_type,sum(income_amount ) as total_income 
from income 
inner join traditionalcouncil on traditionalcouncil.traditionalcouncil_name = income.traditionalcouncil_name 
where financialyear_id = 2 and traditionalcouncil.traditionalcouncil_name= 'DAVHANA' 
group by income_type

所以输出

Income type      Quarter-one Quarter-two  Quarter-three Quarter-four
Customary Fee       20 000        10 000        8 500      4 500
Tribal Levy          800          580            900       650

0 个答案:

没有答案