Alright - well this is not the only way to do this, but it is one.
There are now 4 views and 4 queries.
Views:
- vUser1SightHeard
vUser2SightHeard
vUser3SightHeard
vUser4SightHeard
Queries:
- qryUser1LifeList
qryUser2LifeList
qryUser3LifeList
qryUser4LifeList
The views consist of the following statement:
Code: Select all
SELECT
"AOU Birdlist"."EnglishName",
"Sightings"."Field Trip ID",
"Field Trips"."Date",
"Field Trips"."Location"
FROM "Sightings", "Field Trips", "AOU Birdlist"
WHERE
( "Sightings"."Field Trip ID" = "Field Trips"."ID" AND "AOU Birdlist"."EnglishName" = "Sightings"."Bird Name" )
AND ( "Sightings"."User1Voice" = True )
UNION
SELECT
"AOU Birdlist"."EnglishName",
"Sightings"."Field Trip ID",
"Field Trips"."Date",
"Field Trips"."Location"
FROM "Sightings", "Field Trips", "AOU Birdlist"
WHERE
( "Sightings"."Field Trip ID" = "Field Trips"."ID" AND "AOU Birdlist"."EnglishName" = "Sightings"."Bird Name" )
AND ( "Sightings"."User1Sight" = True )
The only difference with each view is that UserXSight or UserXVoice is used.
Each of the queries then uses the corresponding view with this select statement:
Code: Select all
SELECT
"EnglishName",
CAST( MIN( "Date" ) AS DATE ) AS "FirstSightedDate",
COUNT( "Date" ) AS "SightingsCount"
FROM "vUser1SightHeard"
GROUP BY "EnglishName"
A couple of points:
The views are not particularly optimized, but good enough for a smallish database. If you are using OO.o 2.4 you can edit view definitions now, if you do be sure to set the SQL Direct flag when you try to save the definition.
The queries also use SQL Direct, because they use the CAST function:
CAST( MIN( "Date" ) AS DATE ) AS "FirstSightedDate"
the reason for this is to work around a glitch with Base. Using the MIN function on a DATE type returns an integer and not a DATE type. So I used cast to push it back to a DATE type and the Base query analyzer does not directly support the CAST function, so SQL Direct to turn the base analyzer ( escape processing ) off.
Performance wise - on my machine, under windows the queries run in < 2 seconds cold and < 1 second on subsequent runs.
Edit: One other thing - your odb file ( and the updated one from me ) crash OO.o 3.00 pre-beta m_2 release..I opened an issue on this and listed the link to the original file you used for the earlier post.
The issue can be found at:
http://www.openoffice.org/issues/show_bug.cgi?id=88963 |