pullingteeth
Programmer
Hello, I have the following tables:
book:
book_number
...
book_event:
book_number --> book.book_number
event
timestamp
I devised a form which shows you the number of books which move from {one set of events} to {another set of events} within a specified interval, between a certain set of dates.
E.g., a user might query: "Show me the percentage of books which moved from {received, returned} to {sold} within [2 days] between 8/1/04 and 8/31/04"
The following function returns a query which selects all books which made the transition succesfully. The problem with this is that it doesn't take into consideration weekends; that is, this particular bookstore is CLOSED on weekends, and a book which is received on friday and sells on monday should be a candidate for a query with an interval of two days. So, how can I modify the following to take that into consideration?
(SQL output below)
(for your ease of reading, the query comes out roughly as follows):
Thanks!
book:
book_number
...
book_event:
book_number --> book.book_number
event
timestamp
I devised a form which shows you the number of books which move from {one set of events} to {another set of events} within a specified interval, between a certain set of dates.
E.g., a user might query: "Show me the percentage of books which moved from {received, returned} to {sold} within [2 days] between 8/1/04 and 8/31/04"
The following function returns a query which selects all books which made the transition succesfully. The problem with this is that it doesn't take into consideration weekends; that is, this particular bookstore is CLOSED on weekends, and a book which is received on friday and sells on monday should be a candidate for a query with an interval of two days. So, how can I modify the following to take that into consideration?
(SQL output below)
Code:
Private Function getSet2(d1 As Date, d2 As Date, interval As Integer) As String
getSet2 = "select distinct book_number from book where " _
& " book_number in (select be2.book_number from book_event be2 where " & getSelectedEvents(List17) _
& " and be2.timestamp between #" & d1 & "# and #" & (d2 + interval) & "#" _
& " and be2.book_number in (select be1.book_number from book_event be1 where " _
& getSelectedEvents(List15) _
& " and be1.timestamp between #" & d1 & "# and #" & d2 & "# " _
& " and ((be2.timestamp - be1.timestamp) <= " & interval & ")))" _
& " order by book_number "
End Function
Private Function getSelectedEvents(ByRef list as ListBox)
'return SQL fragment listing all of the book_events
End Function
(for your ease of reading, the query comes out roughly as follows):
Code:
SELECT DISTINCT distinct book_number
FROM book
WHERE book_number IN
(SELECT be2.book_number
FROM book_event be2
WHERE {getSelectedEvents(List17)}
AND be2.timestamp between #8/1/04# AND #9/2/04#
AND be2.book_number IN
(SELECT be1.book_number
FROM book_event be1
WHERE {getSelectedEvents(List15)}
AND be1.timestamp between #8/1/04# AND #8/31/04#
AND ((be2.timestamp - be1.timestamp) <= 2)
)
)
ORDER BY book_number
Thanks!