Subject | Re: Nasty query construct problem |
---|---|
Author | Svein Erling |
Post date | 2003-11-13T08:30:13Z |
--- In firebird-support@yahoogroups.com, Johan wrote:
select distinct dlink, regdate, worker, wtype,
(select t2.nett*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno = 'xxxx') as xxxx_nett,
(select t2.gross*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno = 'xxxx') as xxxx_gross,
(select t2.nett*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno <> 'xxxx' ) as other_nett,
(select t2.gross*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno <> 'xxxx') as other_gross,
from table1 t1
Set
> --- In firebird-support@yahoogroups.com, Lucas Franzen <luc@r...>but
> Hmm...it's even worse I think! In my example I used xxxx and yyyy
> in real life it's xxxx i want in the first column and whatever elseIs what you want something like
> in the second column. The yyyy can be infinit number of variants!
select distinct dlink, regdate, worker, wtype,
(select t2.nett*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno = 'xxxx') as xxxx_nett,
(select t2.gross*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno = 'xxxx') as xxxx_gross,
(select t2.nett*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno <> 'xxxx' ) as other_nett,
(select t2.gross*t2.pcs from table1 t2
where t2.dlink = t1.dlink
and t2.regdate = t1.regdate
and t2.worker = t1.worker
and t2.wtype = t1.wtype
and t2.artno <> 'xxxx') as other_gross,
from table1 t1
Set
> I'm thinking of doing a datamoving routine before my actual sql thatone
> moves each row into a new table and in that move put it in column
> or two and do a per row sum also.grouping.
>
> After that it should be straigh forward for a sql query and
>
> Cheers
> /Johan