Re: [SQL] join problem

2007-06-13 Thread Ales Vojacek
You can do it like this:

select i.ivid, v.eventdate, v.deposit, v.invdate, cai.db,
sum(i.tax) as tax,
sum(i.tax + i.rowtot) as totalP,
(sum(i.tax + i.rowtot) - v.deposit) as balance
  from invoice v
  join cai on v.cusid = cai.cusid
  left outer join
 invoiceitems i
on  v.ivid = i.ivid
  where v.cusid = $cusid
   group by i.ivid,  v.eventdate, v.deposit, v.invdate, cai.db

A.

Aleš Vojáček
FBL Group spol. s r.o.
e-mail: [EMAIL PROTECTED]
mobil: +420603893335



A. R. Van Hook napsal(a):
> I have join problem:
> "select i.ivid, v.eventdate, v.deposit, v.invdate, cai.db,
> sum(i.tax) as tax,
> sum(i.tax + i.rowtot) as totalP,
> (sum(i.tax + i.rowtot) - v.deposit) as balance
>   from invoice v
>   left outer join
>  invoiceitems i
> on  v.ivid = i.ivid
>   where v.cusid = $cusid
> and   v.cusid = cai.cusidgroup by
> i.ivid,  v.eventdate, v.deposit, v.invdate, cai.db
> ERROR:  missing FROM-clause entry for table "cai"
>
> If I add cai to the from clause "from invoice v, cai,  I get
> ERROR:  missing FROM-clause entry for table "cai"
> ERROR:  invalid reference to FROM-clause entry for table "v"
>
> Where do I add the cai table reference???
>
> thanks
>

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [SQL] join problem

2007-06-13 Thread Ales Vojacek
There is not referenced table cai in from clausule.

A. R. Van Hook napsal(a):
> I have join problem:
> "select i.ivid, v.eventdate, v.deposit, v.invdate, cai.db,
> sum(i.tax) as tax,
> sum(i.tax + i.rowtot) as totalP,
> (sum(i.tax + i.rowtot) - v.deposit) as balance
>   from invoice v
>   left outer join
>  invoiceitems i
> on  v.ivid = i.ivid
>   where v.cusid = $cusid
> and   v.cusid = cai.cusidgroup by
> i.ivid,  v.eventdate, v.deposit, v.invdate, cai.db
> ERROR:  missing FROM-clause entry for table "cai"
>
> If I add cai to the from clause "from invoice v, cai,  I get
> ERROR:  missing FROM-clause entry for table "cai"
> ERROR:  invalid reference to FROM-clause entry for table "v"
>
> Where do I add the cai table reference???
>
> thanks
>

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate