Re: Compare two date into the same table
- From: "Michel Walsh" <vanderghast@VirusAreFunnierThanSpam>
- Date: Tue, 4 Oct 2005 07:13:41 -0400
Hi
SELECT pres.referencedate,
pres_1.referencedate,
pres.location,
pres.class,
pres.npeople-Nz(pres_1.npeople, 0) AS diff_people
FROM pres LEFT JOIN pres AS pres_1
ON (pres.class = pres_1.class)
AND
(pres.location = pres_1.location)
WHERE pres.referencedate=#2/1/2005#
AND
Nz(pres_1.referencedate,#1/1/2005# )=#1/1/2005#;
When you use an outer join, and have the unpreserved table, here pres_1, in
the WHERE clause, keep in mind that due to the nature of the outer join,
that table CAN SUPPLY NULL values. Remove the WHERE clause to convince
yourself. If you write the WHERE clause without handling these NULL, you
kill the outer join effect, since the WHERE is likely to remove these
records with a NULL.
Hoping it may help,
Vanderghast, Access MVP
"Alex_Firenze" <alessandro.caforio@xxxxxxxxx> wrote in message
news:1128421444.852715.149360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi all,
> Please, help me to find the right query....
> I would like to compare, within the same table, the figures related to
> a reference date and the previous one...
>
> Example, My table:
> referencedate;location;class;npeople
> 01/01/2005;london;math;100
> 01/01/2005;london;finance;80
> 01/01/2005;london;statistics;50
> 01/01/2005;brighton;statistics;15
> 01/02/2005;london;math;90
> 01/02/2005;london;finance;85
> 01/02/2005;london;statistics;40
> 01/02/2005;brighton;statistics;12
> 01/02/2005;brighton;math;15
>
> At the moment I am not able to manage the new entrances.. Indeed my
> result is:
>
> pres.referencedate; pres_1.referencedate;location;class;diff_people
> 01/02/2005;01/01/2005;london;math;-10
> 01/02/2005;01/01/2005;london;finance;5
> 01/02/2005;01/01/2005;london;statistics;-10
> 01/02/2005;01/01/2005;brighton;statistics;-3
>
> But I would expect also the line:
> 01/02/2005;01/01/2005;brighton;math;15
>
> How can I take into account new Classes or Locations that are appear in
> the reference date but not in the previous??
>
> My query:
>
> SELECT pres.referencedate, pres_1.referencedate, pres.location,
> pres.class, [pres].[npeople]-[pres_1].[npeople] AS diff_people
> FROM pres LEFT JOIN pres AS pres_1 ON (pres.class = pres_1.class) AND
> (pres.location = pres_1.location)
> WHERE (((pres.referencedate)=#2/1/2005#) AND
> ((pres_1.referencedate)=#1/1/2005#));
>
> Thank you in advance
>
> Alex
>
.
- Follow-Ups:
- Re: Compare two date into the same table
- From: Alex_Firenze
- Re: Compare two date into the same table
- References:
- Compare two date into the same table
- From: Alex_Firenze
- Compare two date into the same table
- Prev by Date: Re: Problem designing a query to select shared IDs
- Next by Date: Re: Problem designing a query to select shared IDs
- Previous by thread: Compare two date into the same table
- Next by thread: Re: Compare two date into the same table
- Index(es):
Relevant Pages
|
Loading