SQL Problem [message #604353] |
Sun, 29 December 2013 04:57 |
|
vgupta_2002
Messages: 3 Registered: December 2013
|
Junior Member |
|
|
Hi,
My requirement is that while writing FIFO logic using a single query, if we are not able to fulfill the whole order quantity, the rows should not be inserted into a temporary table
Is there any way in SQL (only in SQL), where I should be able to insert all the records only based on some column in one of the row.
Basically, if my "last row" does not have "quantity remaining" as zero, i should not insert any of the records.
Regards
|
|
|
|
|
Re: SQL Problem [message #604363 is a reply to message #604362] |
Sun, 29 December 2013 07:12 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
So you want to insert only if sum of hrs = 100? Then
SQL> select *
2 from tbl
3 /
START_DT END_DT HRS
--------- --------- ----------
01-JAN-13 31-JAN-13 25
01-FEB-13 28-FEB-13 30
01-MAR-13 31-MAR-13 45
SQL> select *
2 from tbl_tmp
3 /
no rows selected
SQL> insert
2 into tbl_tmp
3 with t as (
4 select tbl.*,
5 sum(hrs) over() total_hrs
6 from tbl
7 )
8 select start_dt,
9 end_dt,
10 hrs
11 from t
12 where total_hrs = 100
13 /
3 rows created.
SQL> select *
2 from tbl_tmp
3 /
START_DT END_DT HRS
--------- --------- ----------
01-JAN-13 31-JAN-13 25
01-FEB-13 28-FEB-13 30
01-MAR-13 31-MAR-13 45
SQL>
SY.
|
|
|
|
|
Re: SQL Problem [message #604373 is a reply to message #604372] |
Sun, 29 December 2013 11:19 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Quote: I have to pro-rate the hrs.
What does this mean?
Can you post an example (and e test case) that cover ALL the cases and explain the result for different "adj hrs".
|
|
|