Re: [GENERAL] join on next row

2006-06-30 Thread Merlin Moncure
On 6/25/06, Sim Zacks <[EMAIL PROTECTED]> wrote: Merlin, Thank you for your input. My original question did specifically mention that the events had to be on the same day. > I need to have a query that gives per employee each event and the event after it if it happened _on the same day_. wh

Re: [GENERAL] join on next row

2006-06-24 Thread Sim Zacks
Merlin, Thank you for your input. My original question did specifically mention that the events had to be on the same day. I need to have a query that gives per employee each event and the event after it if it happened _on the same day_. Secondly, I hadn't seen that syntax in 8.2 yet. That

Re: [GENERAL] join on next row

2006-06-22 Thread Merlin Moncure
On 20 Jun 2006 18:20:55 +0200, Harald Fuchs <[EMAIL PROTECTED]> wrote: In article <[EMAIL PROTECTED]>, Sim Zacks <[EMAIL PROTECTED]> writes: > To get this result set it would have to be an inner join on employee > and date where the second event time is greater then the first. But I > don't want

Re: [GENERAL] join on next row

2006-06-22 Thread Gurjeet Singh
Thanks for pointing it out You are right; I forgot to add that... On 6/20/06, Aaron Evans <[EMAIL PROTECTED]> wrote: sorry to nitpick, but I think that to get this query to do exactly what you want you'll need to add ordering over EventTime on your sub- selects to assure that you get the ne

Re: [GENERAL] join on next row

2006-06-21 Thread Aaron Evans
sorry to nitpick, but I think that to get this query to do exactly what you want you'll need to add ordering over EventTime on your sub- selects to assure that you get the next event and not just some event later event on the given day. -ae On Jun 20, 2006, at 11:12 AM, Gurjeet Singh wrot

Re: [GENERAL] join on next row

2006-06-21 Thread Sim Zacks
Harold, That's brilliant. Sim Harald Fuchs wrote: In article <[EMAIL PROTECTED]>, Sim Zacks <[EMAIL PROTECTED]> writes: I want my query resultset to be Employee,EventDate(1),EventTime(1),EventType(1),EventTime(2),EventType(2) Where Event(2) is the first event of the employee that took place af

Re: [GENERAL] join on next row

2006-06-20 Thread Harald Fuchs
In article <[EMAIL PROTECTED]>, Sim Zacks <[EMAIL PROTECTED]> writes: > I want my query resultset to be > Employee,EventDate(1),EventTime(1),EventType(1),EventTime(2),EventType(2) > Where Event(2) is the first event of the employee that took place > after the other event. > Example > EventIDE

Re: [GENERAL] join on next row

2006-06-20 Thread Martijn van Oosterhout
On Tue, Jun 20, 2006 at 05:13:50PM +0200, Sim Zacks wrote: > Thank you for responding. > I was thinking along those lines as well, though that would be an > absolute performance killer. I shouldn't be too bad, if you have the appropriate indexes defined. However, it seems to me this is the kind

Re: [GENERAL] join on next row

2006-06-20 Thread Gurjeet Singh
I agree about the performance; but it won't be that bad if PG can unnest these subqueries and convert them into join views!!! In that case, these views would return just one row (LIMIT 1), and that is the best a developer can do to help the optimizer make the decision. If the optimizer knows th

Re: [GENERAL] join on next row

2006-06-20 Thread Sim Zacks
Thank you for responding. I was thinking along those lines as well, though that would be an absolute performance killer. Gurjeet Singh wrote: It would have been quite easy if done in Oracle's 'lateral view' feature. But I think it is achievable in standard SQL too; using subqueries in the sele

Re: [GENERAL] join on next row

2006-06-20 Thread Gurjeet Singh
It would have been quite easy if done in Oracle's 'lateral view' feature. But I think it is achievable in standard SQL too; using subqueries in the select-clause. Try something like this: select Employee, EventDate, EventTime as e1_time, EventType as e1_type, (

[GENERAL] join on next row

2006-06-19 Thread Sim Zacks
I am having brain freeze right now and was hoping someone could help me with a (fairly) simple query. I need to join on the next row in a similar table with specific criteria. I have a table with events per employee. I need to have a query that gives per employee each event and the event after