显示每月而不是特定数据。需要小的调整

时间:2014-01-18 08:45:15

标签: sql

我希望按作业类型显示每月的总发票数,但似乎每月的总发票量都在显着。我只是想显示每个工作类型的总数。

这是我到目前为止所做的:

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的字段:

  • 日期
  • job_no - 通过tjobs表连接到jobtypes字段
  • JOB_NAME
  • CLIENT_NAME
  • 金额
  • ppaid
  • inv_no
  • 概率
  • 注释
  • 接触
  • 位置
  • YYMM

1 个答案:

答案 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`