1

可能重复:
php、postgresql、mysql

我想过滤查询以产生如下结果:

sum of amount_to_be_paid, contractor name, sum of amount paid.

我的问题出在表映射中。它产生双重结果 bcozcontractor_task 的表有 2 个条目具有相同的承包商但不同的工作类型。请告诉我如何获得承包商的单一结果,即使他从事不同的任务。

询问:

select distinct contractors.name, cont.total,cp.amount_paid
                FROM
                (
                  select contractor_id,sum(amount_to_be_paid) as total
                  from contractor_tasks left join worktypeids as wt on worktypeid_id = wt.id where wt.project_id=2
                  group by contractor_id
                )cont
                left join
                (
                  select project_id,contractor_id,sum(amount_paid) as amount_paid
                  from contractor_payments 
                  group by contractor_id,project_id
                )cp

                    on cont.contractor_id= cp.contractor_id
                              left join contractors on cont.contractor_id=contractors.id
4

0 回答 0