0

我被困在一个查询中。我不知道究竟是什么问题..任何 1 都可以帮助我吗?

这是代码:

当我运行查询时,它抛出错误:错误:关系“承包商”不存在第 5 行:来自“承包商”

select  cont.name, cont.total,cp.contractor_id,cp.amount_paid,wt.id
                FROM
                (
                  select name,sum(amount_to_be_paid) as total
                  from "CONTRACTORS"
                  group by name
                ) cont
                left join
                (
                  select contractor_id,sum(amount_paid) as amount_paid
                  from "CONTRACTOR_PAYMENTS" 
                  group by contractor_id
                ) cp

                    on cont.id= cp.contractor_id
                              left join worktypeids as wt on cont.worktypeid_id = wt.id AND wt.project_id=2
4

2 回答 2

0

你也可以添加表结构吗?

在名为 as 的第一个别名中cont,即 join with cp,因此对于 cont,您还需要选择id列。

更好的发布表结构以及你想要的输出?

于 2012-12-25T05:01:45.163 回答
0

试试这个

select  cont.name, cont.total,cp.contractor_id,cp.amount_paid,wt.id
                FROM
                (
                  select  name,id, sum(amount_to_be_paid) as total
                  from contractors group by name,id
                ) cont
                left join
                (
                  select contractor_id,sum(amount_paid) as amount_paid
                  from contractor_payments
                  group by contractor_id
                ) cp

                  on cont.id = cp.contractor_id
                              left join worktypeids as wt on cont.worktypeid_id = wt.id AND wt.project_id=2
于 2012-12-25T05:05:13.407 回答