pacard
Vendor
- Jan 25, 2007
- 9
Hello All-Hoping for a little guidance. I'm trying to generate a list of persons, their property, unit and their payments within a date range. My problem is that the payments are being duplicated if they lived in more than one unit. Is there a way to only include those units that actually had payments associated with them? Here's the query:
SELECT p.property, u.unit_name AS UNIT, a.app_name as Client, t.amt_total AS PMT_AMT, t.trans_date, tt.ttype_name
FROM properties p, units u, apps a, occupants o, trans t, trantypes tt
WHERE p.id = 3
AND p.id = u.property_id
AND a.id = o.app_id
AND u.unit_id = o.unit_id
AND t.trans_date BETWEEN '8/15/2006' and '1/07/2007'
AND tt.ttype_name = 'PAYMENT'
AND t.ttype_id = tt.ttype_id
AND t.app_id = a.id
ORDER BY 3,5 ASC
Here's an example of the output
unit client pmt_amt trans_date
546C ANDERSON, GARRY $315.00 8/17/2006
540D ANDERSON, GARRY $315.00 8/17/2006
546C ANDERSON, GARRY $322.50 9/2/2006
540D ANDERSON, GARRY $322.50 9/2/2006
As you can see the payments have shown up twice because at one time this person lived in a second unit.
ANY HELP is much appreciated!
pc
SELECT p.property, u.unit_name AS UNIT, a.app_name as Client, t.amt_total AS PMT_AMT, t.trans_date, tt.ttype_name
FROM properties p, units u, apps a, occupants o, trans t, trantypes tt
WHERE p.id = 3
AND p.id = u.property_id
AND a.id = o.app_id
AND u.unit_id = o.unit_id
AND t.trans_date BETWEEN '8/15/2006' and '1/07/2007'
AND tt.ttype_name = 'PAYMENT'
AND t.ttype_id = tt.ttype_id
AND t.app_id = a.id
ORDER BY 3,5 ASC
Here's an example of the output
unit client pmt_amt trans_date
546C ANDERSON, GARRY $315.00 8/17/2006
540D ANDERSON, GARRY $315.00 8/17/2006
546C ANDERSON, GARRY $322.50 9/2/2006
540D ANDERSON, GARRY $322.50 9/2/2006
As you can see the payments have shown up twice because at one time this person lived in a second unit.
ANY HELP is much appreciated!
pc