Re: query help
From: Anith Sen (anith_at_bizdatasolutions.com)
Date: 07/19/04
- Next message: Steve Kass: "Re: Adjacency List and nested set -- J celko example -- Guru needed"
- Previous message: Anon-E-Moose: "Re: To AutoIncrement or not to AutoIncrement"
- In reply to: Alex: "Re: query help"
- Next in thread: Alex: "Re: query help"
- Reply: Alex: "Re: query help"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 19 Jul 2004 10:55:33 -0500
Alex,
In the future, please include all relevant information in a simplified
format so that others can help you better. Based on your narrative and
sample data, I am assuming you have the data specific to Donations, Prayer
Requests, Gifts in three tables. Since you haven't given much specifics
about the key columns ( not the identity values, but the column or set of
columns which uniquely identify a donation, request or gift ) , unique
constraints and references, I am assuming you need the aggregate values for
each of these for all the dates within a given period. Using a calendar
table ( check out the archives on how you can come up with one easily ) you
can do something along the lines of :
SELECT dt,
( SELECT COUNT( * ) FROM Donations d1
WHERE d1.dtcol = c1.dt AND d1.usr = 'joe' ),
( SELECT COUNT( * ) FROM DonorNeeds d1
WHERE d1.dtcol = c1.dt AND d1.usr = 'joe' ),
( SELECT COUNT( * ) FROM DonorGifts d1
WHERE d1.dtcol = c1.dt AND d1.usr = 'joe' ),
FROM Calendar c1
WHERE c1.dt BETWEEN '20040101' AND '20040131'
You can simplify them using CASE expressions if the referencing columns
among the three tables as well.
-- Anith
- Next message: Steve Kass: "Re: Adjacency List and nested set -- J celko example -- Guru needed"
- Previous message: Anon-E-Moose: "Re: To AutoIncrement or not to AutoIncrement"
- In reply to: Alex: "Re: query help"
- Next in thread: Alex: "Re: query help"
- Reply: Alex: "Re: query help"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|