I have this SQL:
SELECT A.zdesc, A.zone, ;
B.cdesc, B.ctype, ;
NVL(B.ncnt,0) AS pccnt, ;
NVL(C.ncnt,0) AS dccnt, ;
NVL(D.ncnt,0) AS ptcnt, ;
NVL(D.ncnt,0) AS dtcnt ;
FROM allzones A, p_ccnt B, d_ccnt C, p_tcnt D, d_tcnt E ;
INTO CURSOR zsum ;
WHERE ???
The goal is to fill in the where, or, preferably, turn it into JOINs.
Tables:
A - A list of all the zones and descriptions
B - PU zone, category, # of distinct clients in each zone/cat
C - DO zone, category, # of distinct clients in each zone/cat
D - PU zone, category, # of trips in each zone/cat
E - DO zone, category, # of trips in each zone/cat
I'm trying to get a cursor with all the zones, and for each zone a list of categories, and for each category # clients in pickup zone and dropoff zone, and # trips in each.
So I'd have:
Zone: A11
Cat CPU CDO TPU TDO
AMB 1 1 2 2
NAMB 3 1 1 3
I'd really appreciate any help. I've been working on it a while and I just can't figure out what to join to what and in what order.
Thanks,
-Michelle