From: Steve Richter

-- this view selects all of the owner's events
create view OwnerItemEvents as
(
select a.OwnerName, a.itemId,
b.eventText, b.eventTs
from ItemOwner a
join ItemEvents b
on a.itemId = b.itemId
order by a.OwnerName, a.itemId, b.eventTs
) ;

Nope, this is wrong. INVENTORY and OWNER don't have a 1-to-1 relationship.
OWNER->INVENTORY is 1-to-N, with the only relationship being relative time:

OWNER 1 "Joe" at 12:01
INVENTORY 1 "Event 1" at 12:02
INVENTORY 1 "Event 2" at 12:03
INVENTORY 1 "Event 3" at 12:04
OWNER 1 "Frank" at 12:10
INVENTORY 1 "Event 4" at 12:11
INVENTORY 1 "Event 5" at 12:12

The only thing that makes Events 1-3 belong to Joe is the fact that the
OWNER record for Joe occurred before those events. Events 4 and 5 belong to
Frank because the Frank OWNER record occurred before Event 4.

This is why I noted in my previous post that this problem is perfect for
matching records. The primary key is control number (in this case, 1),
while the secondary key is time. You could write this entire report without
a single C-spec.

The funny thing is that, if you don't understand matching record logic,
trying to figure out the SQL is tough. Note that it's the old native I/O
RPG dinosaur who figured out the right SQL code <grin>.

Joe



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.