[SQL] join on next row

2006-06-21 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

Re: [SQL] join on a like

2006-05-02 Thread Sim Zacks
I guess the real question is: what is more efficient - a join on a LIKE or a PLPGSQL function that has 2 loops, 1 for each bottom level child and one that takes the substring of that child one character at a time to get each parent? It sounds like you are saying that the join will actaully use

[SQL] join on a like

2006-05-02 Thread Sim Zacks
A friend suggested that I use the Like predicate as part of my join condition and I was wondering if that was wise. For example, I have a column that describes the level of an event. There is A,B,C and then they can have children, such as AA,AB,BA,BB and they can all have children as well. So

[SQL] join if all matches

2005-11-26 Thread Sim Zacks
I am trying to figure out an sql statement and I was hoping someone could help. I'm having brainfreeze right now. Table Rules RuleID RuleName Table RuleAgents RuleAgentID RuleID Agent Table RuleActions RuleActionID RuleID Action I am passing in an array of agents

Re: [SQL] scroll cursor bug or me?

2005-06-27 Thread Sim Zacks
It seems to me that scroll cursors are not valid in plpgsql. The following query in PGAdmin works. run one line at a time. begin work; declare bob scroll cursor for select * from testtbl; fetch forward 5 from bob; fetch prior from bob; rollback work; "Larry Morroni" <[EMAIL PROTECTED]> wrot

[SQL] plpython setof

2005-05-17 Thread Sim Zacks
Anybody know how to return a setof from a plpython function? ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

[SQL] group by before and after date

2005-03-13 Thread Sim Zacks
I have 2 tables 1 has a date field and component need by that date and the other has all the upcoming orders. I am trying to build a query that will give me the Date and ComponentNeed and also how many components have been ordered before that date and how many after. PostGreSQL is telling me I need

Re: [SQL] group by before and after date

2005-03-13 Thread Sim Zacks
sum(coalesce(case when b.DatePromisedBy >a.DueDate then coalesce(b.QuantityOrdered,0)-coalesce(b.DeliveredSum,0) end,0)) as ExpectedAfter from TableA a left join TableB on a.partid=b.partid group by a.DueDate,a.PartID,a.AmountNeeded,a.CurrentStock "Sim Zacks" <[EMAIL PROTECTED