我希望按作业类型显示每月的总发票数,但似乎每月的总发票量都在显着。我只是想显示每个工作类型的总数。
这是我到目前为止所做的:
select `vinvoices`.`yymm` AS `yymm`,
`vinvoices`.`location` AS `job_location`,
`vinvoices`.`job_no` AS `job_no`,
format(sum(`vinvoices`.`amount`),0) AS `amount`,
`tjobtypes`.`type_name` AS `type` from ((`vinvoices` join `tjobs` on((`tjobs`.`job_no` = `vinvoices`.`job_no`))) join `tjobtypes` on((`tjobtypes`.`type_no` = `tjobs`.`type_no`)))
group by `vinvoices`.`yymm`,`vinvoices`.`location`
以下是vinvoices的字段:
答案 0 :(得分:0)
我认为你需要写COUNT()
而不是SUM()
,如下所示:
select `vinvoices`.`yymm` AS `yymm`,
`vinvoices`.`location` AS `job_location`,
`vinvoices`.`job_no` AS `job_no`,
format(COUNT(`vinvoices`.`amount`),0) AS `amount`,
`tjobtypes`.`type_name` AS `type` from ((`vinvoices` join `tjobs` on((`tjobs`.`job_no` = `vinvoices`.`job_no`))) join `tjobtypes` on((`tjobtypes`.`type_no` = `tjobs`.`type_no`)))
group by `vinvoices`.`yymm`,`vinvoices`.`location`