Query help first two rows
i need to sort desc order by date and need to take two rows only
id date
1 1/2/1994
2 2/2/2000
3 1/5/88
4 6/5/2006
i need out put like this
id date
4 6/5/2006
2 2/2/2000
plz give query with good perfomence thanks
You can use any one of the below query which performs better for you
SQL> with t
2 as
3 (
4 select 1 id,to_date('1/2/1994','dd/mm/yyyy') dt from dual
5 union all
6 select 2,to_date('2/2/2000','dd/mm/yyyy') from dual
7 union all
8 select 3,to_date('1/5/88','dd/mm/yyyy') from dual
9 union all
10 select 4,to_date('6/5/2006','dd/mm/yyyy') from dual
11 )
12 select * from
13 (
14 select * from t
15 order by 2 desc
16 )
17 where rownum <=2
18 /
ID DT
4 06-MAY-06
2 02-FEB-00
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9 Card=2 Bytes=24)
1 0 COUNT (STOPKEY)
2 1 VIEW (Cost=9 Card=4 Bytes=48)
3 2 SORT (ORDER BY STOPKEY) (Cost=9 Card=4 Bytes=48)
4 3 VIEW (Cost=8 Card=4 Bytes=48)
5 4 UNION-ALL
6 5 FAST DUAL (Cost=2 Card=1)
7 5 FAST DUAL (Cost=2 Card=1)
8 5 FAST DUAL (Cost=2 Card=1)
9 5 FAST DUAL (Cost=2 Card=1)
Statistics
1 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
416 bytes sent via SQL*Net to client
496 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
2 rows processed
SQL> with t
2 as
3 (
4 select 1 id,to_date('1/2/1994','dd/mm/yyyy') dt from dual
5 union all
6 select 2,to_date('2/2/2000','dd/mm/yyyy') from dual
7 union all
8 select 3,to_date('1/5/88','dd/mm/yyyy') from dual
9 union all
10 select 4,to_date('6/5/2006','dd/mm/yyyy') from dual
11 )
12 select id,dt
13 from
14 (
15 select id,dt,row_number() over(order by dt desc) rn from t
16 order by 2 desc
17 )
18 where rn <=2
19 /
ID DT
4 06-MAY-06
2 02-FEB-00
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=4 Bytes=100
1 0 VIEW (Cost=8 Card=4 Bytes=100)
2 1 WINDOW (SORT PUSHED RANK) (Cost=8 Card=4 Bytes=48)
3 2 VIEW (Cost=8 Card=4 Bytes=48)
4 3 UNION-ALL
5 4 FAST DUAL (Cost=2 Card=1)
6 4 FAST DUAL (Cost=2 Card=1)
7 4 FAST DUAL (Cost=2 Card=1)
8 4 FAST DUAL (Cost=2 Card=1)
Statistics
1 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
416 bytes sent via SQL*Net to client
496 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
2 rows processed
Similar Messages
-
Want to fetch first two row from database
i'm having a database with multiple rows. I want to fetch first two rows form it dynamically, what should i have to do???.plz help....
the data comes from external source and updating the database, at the same time i've to read only first two rows, plz explain.
-
When using private browsing to view image results in Safari 5.1.3, only the first two rows of results are visible, the following four or so rows display greyed out place holders, the remainder of the results page is blank, and the safe search button is inoperable. When I turn off private browsing and refresh the page, everything works again.
Anyone else having this problem?I have got the same behaviour after the last Safari Update to 5.1.3. It seems that Safari now handles some scripts in a new way. If you debug the Google Website, you will see, that there is some Javascript Error, that seems to prevent to write into local cache. After some searching I wasn't able to finde a solution for this problem, other then disabling Javascript while private browsing to prevent the script loading. You then are able to use Google with the old layout. The option to disable JavaScript can be found in the Menu "Developer", wich has to be enabled in Safari in the options first.
In my opinion this is a bug that is now occuring, because Apple changed something in private browsing and that has to be fixed by Google now, to run again. Or we will have to wait for 5.1.4, as you can read online Apple will change and bugfix the javascript engine in that version, perhaps this fixes the problem as well. I hope so!
If anyone is in the developer program perhaps you could test this with the beta of 5.1.4 and tell us if it works. -
How can I calculate the sum of the first two rows in a table?
I have a table with a repeating row that, when data is merged, always has three rows:
Support type 1
1,234,456
Support type 2
221,556
Interest
11.222
I have a field where I want to show the sum of Support types 1 and 2.
I do not want to add the interest to this.
I'm using FormCalc with the following script on the calculate event of the Total field, which is in the same subform but not in the table:
data.JP_Page1.subform_Hidden.sub_SupportTotals.NumericField1::calculate - (FormCalc, client)
$.rawValue = Sum(subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[0].SUBTOTAL, subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[1].SUBTOTAL)
I've tried this using both decimal and numeric field types, neither work.
I feel like I must be hitting a syntax issue, but the code checker isn't exposing it.
Can anyone help me figure out what is wrong with my script?
Thanks!
JanetYou don't need to do Sum for this, you should use Sum for all rows purpose only..
$.rawValue = subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[0]. SUBTOTAL + subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[1].SUBT OTAL -
Query help, subtract two query parts
Hi,
I am beginner of PL/SQL and have a problem I couldn’t solve:
Table (op_list):
Item - Amount - Status
Item1 - 10 - in
Item2 - 12 - in
Item3 - 7 - in
Item1 - 2 - out
Item2 - 3 - out
Item1 - 1 - dmg
Item3 - 3 - out
Item1 - 2 - out
Item2 - 5 - out
Item2 - 2 - in
Item3 - 1 - exp
Would like to get result of query (subtract amount of 'out/dmg/exp' from 'in' ):
Item - Amount left
Item1 - 5
Item2 - 6
Item3 - 3
I wrote code that returns sum of all incoming items and sum all out/dmg/exp items, but couldn’t solve how to subtract one part of querry from another. Or maybe there is a better way. Also worried what happens if there is no 'out/dmg/exp' only 'in'
select item.name, sum(op_list.item_amount)
from op_list
inner join item
on op_list.item = item.item_id
where op_list.status = 'in'
group by item.name
union
select item.name, sum(op_list.item_amount)
from op_list
inner join item
on op_list.item = item.item_id
where op_list.status = 'out'
or op_list.status = 'dmg'
or op_list.status = 'exp'
group by item.name
Return:
Item1 - 10 [10 in]
Item1 - 5 [2+1+2]
Item2 - 14 [12+2]
Item3 - 7
Item3 - 4 [3+1]
Thanks in advanceHi,
We can also use simple inline views to get what we need.
select a.item,a.amount-b.amount Balance from
(select item,sum(amount) Amount from op_list
where status = 'in'
group by item) a,
(select item,sum(amount) Amount from op_list
where status in ('out','dmg','exp')
group by item) b
where
a.item=b.item
order by item;
ITEM BALANCE
Item1 5
Item2 6
Item3 3Regards,
Prazy -
Query help, getting the row that fits the date
Here is a sample dataset
CREATE TABLE #TESTDATA (
TableID INT IDENTITY(1,1),
SomeCode VARCHAR(50),
SomeDescription VARCHAR(50),
EffectiveFrom DATE
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah1','2014-01-03')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah2','2014-01-10')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah3','2014-01-15')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah4','2014-01-30')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah1','2014-01-01')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah2','2014-01-05')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah3','2014-01-20')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah4','2014-01-30')
The dates in the EffectiveFrom column indicates the date from which SomeDescription applies to SomeCode. So when someone asks what was the SomeDescription for SomeCode = A on 2014-01-04, the answer would be blah1.
On '2014-01-10', it would be blah2.
Anything on or past '2014-01-30' would be blah4.
Nothing if before '2014-01-03'
So how would I do a query that says give me every SomeCode and SomeDescription pair that was effective on @Date. I purposely left out the EffectiveTo date which would make this query very easy by doing a between clause.Are you looking for the below?
CREATE TABLE #TESTDATA (
TableID INT IDENTITY(1,1),
SomeCode VARCHAR(50),
SomeDescription VARCHAR(50),
EffectiveFrom DATE
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah1','2014-01-03')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah2','2014-01-10')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah3','2014-01-15')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('A','blah4','2014-01-30')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah1','2014-01-01')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah2','2014-01-05')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah3','2014-01-20')
INSERT #TESTDATA (SomeCode,SomeDescription,EffectiveFrom) VALUES ('B','blahblah4','2014-01-30')
Declare @somecode varchar(10) = 'A', @sDate date = '2014-01-14'
Select Top 1 * From #TESTDATA where SomeCode = @somecode and EffectiveFrom <=@sDate Order by EffectiveFrom desc
Drop table #Testdata -
Would Hierarchical query help compressing rows in the following table?
Hi,
I have a table which looks like the following
key1 sdt edt val1
1 1/1/2000 2/1/2000 1
1 2/1/2000 3/1/2000 1
1 3/1/2000 4/1/2000 2
1 4/1/2000 5/1/2000 2
1 5/1/2000 6/1/2000 2
1 6/1/2000 7/1/2000 3
1 7/1/2000 8/1/2000 1
basically for a given key between given dates it had a value, kinda historical
table. As you can see first two rows can be compressed into
one. First two rows should become one (1, 1/1/2000, 3/1/2000, 1) as it had same
values between first two rows. Same with the next three row
(1,3/1/2000,6/1/2000,2). I did this to get to the following result.
SELECT key1, MIN(sdt), MAX(edt), val1
FROM (SELECT LEVEL, SYS_CONNECT_BY_PATH( TO_CHAR(sdt,'yyyymmdd') , '/') path,
key1, sdt, edt, val1
FROM myt t1
START WITH sdt = (SELECT MIN(sdt) FROM myt t2 WHERE t2.key1 = t1.key1
AND t2.val1 = t1.val1)
CONNECT BY sdt = PRIOR edt
AND key1 = PRIOR key1
AND val1 = PRIOR val1
GROUP BY key1, SUBSTR(path,2,8), val1;
key1 sdt edt val1
1 1/1/2000 3/1/2000 1
1 3/1/2000 6/1/2000 2
1 6/1/2000 7/1/2000 3
1 7/1/2000 8/1/2000 1
I was wondering if there is a better way to do this. What would help to tune this.
Thanks in advance.SQL> select * from level_test;
KEY1 ST_DT ED_DT VAL
1 01-JAN-2000 01-FEB-2000 1
1 01-FEB-2000 01-MAR-2000 1
1 01-MAR-2000 01-APR-2000 2
1 01-APR-2000 01-MAY-2000 2
1 01-MAY-2000 01-JUN-2000 2
1 01-JUN-2000 01-JUL-2000 3
1 01-JUL-2000 01-AUG-2000 1
7 rows selected.
SQL> select key1, val, min(st_dt) min, max(ed_dt) max
2 from (
3 select key1, val, st_dt, ed_dt,
4 add_months(ed_dt, -(row_number() over(partition by key1, val order by st_dt))) am
5 from level_test
6 )
7 group by key1, val, am
8 /
KEY1 VAL MIN MAX
1 1 01-JAN-2000 01-MAR-2000
1 1 01-JUL-2000 01-AUG-2000
1 2 01-MAR-2000 01-JUN-2000
1 3 01-JUN-2000 01-JUL-2000
SQL> select * from t;
KEY1 ST_DT ED_DT VAL
1 01-JAN-2000 01-FEB-2000 10
1 01-FEB-2000 01-MAR-2000 10
1 01-MAR-2000 01-APR-2000 10
1 01-APR-2000 01-MAY-2000 10
1 01-MAY-2000 01-JUN-2000 10
2 01-JAN-2000 01-FEB-2000 10
2 01-FEB-2000 01-MAR-2000 10
2 01-MAR-2000 01-APR-2000 11
2 01-APR-2000 01-MAY-2000 11
2 01-MAY-2000 01-JUN-2000 12
10 rows selected.
SQL> select key1, val, min(st_dt) min, max(ed_dt) max
2 from (
3 select key1, val, st_dt, ed_dt,
4 add_months(ed_dt, -(row_number() over(partition by key1, val order by st_dt))) am
5 from t
6 )
7 group by key1, val, am
8 /
KEY1 VAL MIN MAX
1 10 01-JAN-2000 01-JUN-2000
2 10 01-JAN-2000 01-MAR-2000
2 11 01-MAR-2000 01-MAY-2000
2 12 01-MAY-2000 01-JUN-2000Rgds. -
Need to merge the below two rows
Hi,
I have a sample data as shown below:
ID OBJID ACT_CODE ADDNL_INFO ENTRY_TIME
2523540 333003736 900 from WIP default to Queue PSD1. 1/3/2012 15:07
2523540 333003271 100 100 from Queue PSD1 to WIP For assigment. 1/3/2012 15:43
2523540 333003744 900 900 from WIP default to Queue PSD1. 1/3/2012 15:49
2523540 333004966 100 100 from Queue PSD1 to WIP For assigment. 1/3/2012 16:04
I need to merge the first two rows and get a single record for each "from" and "to" as shown below (desired output)
ID_NUMBER ADDNL_INFO ENTRY_TIME EXIT_TIME TOTAL TIME
2523540 PSD1 1/3/2012 15:07 1/3/2012 15:43 0.025069444
2523540 PSD1 1/3/2012 15:49 1/3/2012 16:04 0.010231481
I have used function on the addnl_info column to display only the name of the queue "PSD1"
(SUBSTR(ADDNL_INFO, INSTR(ADDNL_INFO, 'PSD1'), LENGTH('PSD1'))) QUEUE_NAME
Can any one help me out in getting the desired output.Below is a solution to your query:
drop table test_Table;
create table test_Table
ID number,
objid number,
act_code number,
addl_info varchar2(500),
entry_time timestamp
insert into test_Table values (2523540, 333003736, 900, 'from WIP default to Queue PSD1.', to_timestamp('1/3/2012 15:07', 'DD/MM/YYYY HH24:MI'));
insert into test_Table values (2523540, 333003271, 100, 'from Queue PSD1 to WIP For assigment.', to_timestamp('1/3/2012 15:43', 'DD/MM/YYYY HH24:MI'));
insert into test_Table values (2523540, 333003744, 900, 'from WIP default to Queue PSD1.', to_timestamp('1/3/2012 15:49', 'DD/MM/YYYY HH24:MI'));
insert into test_Table values (2523540, 333004966, 100, 'from Queue PSD1 to WIP For assigment.', to_timestamp('1/3/2012 16:04', 'DD/MM/YYYY HH24:MI'));
select * from test_table;
select id, addl_info, entry_time, exit_time, total_time
from
select a.id, a.objid, 'PSD1' addl_info, a.entry_time, lead(a.entry_time, 1, null) over (order by a.entry_time) exit_time,
lead(a.entry_time, 1, null) over (order by a.entry_time) - a.entry_time total_time, DECODE(a.act_code, 900, 'D', 'ND') disp
from test_Table a
where a.id = 2523540
where disp = 'D';
ID ADDL_INFO ENTRY_TIME EXIT_TIME TOTAL_TIME
2523540 PSD1 01-MAR-12 03.07.00.000000000 PM 01-MAR-12 03.43.00.000000000 PM 0 0:36:0.0
2523540 PSD1 01-MAR-12 03.49.00.000000000 PM 01-MAR-12 04.04.00.000000000 PM 0 0:15:0.0I see a shortcoming in the design:
1. For "WIP default to Queue PSD1" there are two records, both containing different OBJID but same ID, which in ideal case should not happen. You MUST have a COMPOSITE key on ID and OBJID; This shall help you to identify the distinct records.
My solution is not perfect as it is based on the ENTRY TIME. The reason being SIMPLE Ordering by the OBJID would not lead to a correct difference in the Transaction Time (referred by you as TOTAL_TIME.); Hence, for this reason I had to use ENTRY_TIME to correctly get the total_time.
If you wish you may follow the solution else I shall always recommend to change the Table Design and follow the correct approach.
If you are changing the Table design then following shall be a solution:
select id, addl_info, entry_time, exit_time, total_time
from
select a.id, a.objid, 'PSD1' addl_info, a.entry_time, lead(a.entry_time, 1, null) over (order by a.id, a.objid) exit_time,
lead(a.entry_time, 1, null) over (order by a.entry_time) - a.entry_time total_time, DECODE(a.act_code, 900, 'D', 'ND') disp
from test_Table a
where disp = 'D';Regards,
P. -
Returning two rows with one column containing only one place
Dear all;
I have a query that returns two rows similar to this below
ID PLACE PROGRAM
A NEWYORK PROGRAM A
A NEWYORK PROGRAM B
I would like this instead
ID PLACE PROGRAM
A NEWYORK PROGRAM A
PROGRAM B
All help is appreciated. Thank you.Edited by: user13328581 on Mar 22, 2011 11:52 AMuser13328581 wrote:
WOW...THanks a lot Solomon, I have never used partitions and row_number in such a manner...can you please explain your logic.Sure:
row_number() over(partition by id order by place,program)This will take all rows returned by the query andsplit them into buckets (partitions) by id. Inside each bucket it will order rows by place and program and assign them row numbers. So for each ID row number 1 will be row with first (alphabetically) place first programt. And this is the row where we want ID to show up. That is why we wrap the above analytic function in CASE statement which will do exactly that. Now:
row_number() over(partition by id,place order by program)does pretty much the same just bucket is ID and PLACE combination. So for each such combination we want to show only for the first (alphabetically) programt.
Now notice in ORDER BY clause I prefix ID and PLACE with table alias. You must do it since otherwise query alias ID and PLACE will take precedence resulting in wrong sort order (remember we nulled all ID and PLACE except for row number 1).
SY. -
Merge Two Rows of a table to One row but into two columns
Hi
I Am struck in writing a query to merge two rows into two columns of one row.
Here is the Sample data i am working with,
Col 1 Col 2 Col3 Col4 Col Col6
5000 573-3000 2 0 Phone
5000 573-3036 1 0 Fax
5000 893-5703 3 0 WOrk
3000 232-5656 1 0 Phone
3000 353-5656 2 0 FAx
Here Col,Col3,Col4 form the Key.
now wht i am trying to do is to Merge these type of rows put them into Columns P,F,W,E respectively to achive a Structure as below
Col1 P F W
5000 573-3000 573-3036 893-5703
3000 232-5656 353-5656
Can you please help me how could i do this.
I am pretty ordinary at writing SQL's.
Thanks a Lot in Advance
Message was edited by:
SreebhushanSearch the forum for PIVOT and you'll find plenty of examples.
-
Hi All,
I have below table
IT_Terms_First_Date
IT_Terms_Last_Date
DI_Debt_Num
IT_Terms_Seq_Num
200501
201101
1000
131
200512
203412
1001
131
200503
204209
1003
131
200507
201001
1004
131
200510
202710
1005
131
200506
202412
10020
131
197910
198310
257000
101
198009
202909
298000
101
198101
202908
298000
103
198105
202910
298000
104
199109
201309
578000
101
199204
201110
600000
101
198009
201010
298010
101
198105
204010
298010
104
201011
202909
298010
103
I need to check whether my DI_Debt_Num having Ovelaping or not for each DI_Debt_Num,
at this moment we are checking each row in loop and usnig function
exec @Overlap1=[DffMonths] @ITtermsLD,@ITtermsNextFD
exec @Overlap2=[DffMonths] @ITtermsFD,@ITtermsNextFD
exec @Overlap3=[DffMonths] @ITtermsFD,@ITtermsNextLD
if(@Overlap1>0 and (@Overlap2<=0 OR @Overlap3<0))
BEGIN
SET @CheckOverlap=1
END
here @ITtermsLD is the IT_Terms_Last_Date of the current DI_Debt_Num,@ITtermsNextFD is the IT_Terms_First_Date of the next row. @ITtermsFD is the IT_Terms_First_Date of the current month
if we consider the 298000 DI_Debt_Num we have 3 IT_Terms_Seq_Num 101,103,104
in this senario we need to check only the first 2 rows from that itself we can identify it is overlapped ,but when we consider the 298010 we need to check all 3 IT_Terms_Seq_Num 101,103,104 if we consider first two rows 101 & 103 it is not overlapped.Then
we have to check first row with 3rd row ie 104 and it is overlapped.We are checking the overlap senario for DI_Debt_Num having multipple IT_Terms_Seq_Num rows
Some situation first row may not be overlapped with other rows .Then we have to check the 2nd row with the next rows in the same way we are doing for first row
My aim is to covert this looping method to a select query to improve my query performance
Thanks in advance
RoshanPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea,
do you? Temporal data should use ISO-8601 formats. You failed again! I will guess that your dates are months. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
>> I have below table <<
This is not a table! Where is the DDL? This picture has no name. Not even a name!! There is no “seq_nbr” in RDBMS; it has to be a “<something in particular>_seq” and there are no duplicates in a sequence.
My guess is that each di_debt_nbr has a sequence within its range. I will call it the “foobar_seq” for lack of a name.
My next guess is that your dates are really months and you do not know about using a report period table. This idiom gives a name to a range of dates that is common to the entire enterprise.
CREATE TABLE Something_Report_Periods
(something_report_name CHAR(10) NOT NULL PRIMARY KEY
CHECK (something_report_name LIKE <pattern>),
something_report_start_date DATE NOT NULL,
something_report_end_date DATE NOT NULL,
CONSTRAINT date_ordering
CHECK (something_report_start_date <= something_report_end_date),
etc);
These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
Here is another guess at what you want, if you knew what a table is:
CREATE TABLE DI_Debts
(it_terms_first_date CHAR(10) NOT NULL
REFERENCES Report_Period (month_name),
it_terms_last_date CHAR(10) NOT NULL
REFERENCES Report_Period (month_name),
CHECK (it_terms_first_date <= it_terms_last_date),
di_debt_nbr INTEGER NOT NULL,
foobar_seq INTEGER NOT NULL,
PRIMARY KEY (di_debt_nbr, foobar_seq));
INSERT INTO DI_Debts
VALUES
('2005-01-00', '2011-01-00', 1000, 1),
('2005-12-00', '2034-12-00', 1001, 1),
('2005-03-00', '2042-09-00', 1003, 1),
('2005-07-00', '2010-01-00', 1004, 1),
('2005-10-00', '2027-10-00', 1005, 1),
('2005-06-00', '2024-12-00', 100201, 1),
('1979-10-00', '1983-10-00', 257000, 1),
('1980-09-00', '2029-09-00', 2980001, 1),
('1981-01-00', '2029-08-00', 298000, 1),
('1981-05-00', '2029-10-00', 298000, 2),
('1991-09-00', '2013-09-00', 578000, 1),
('1992-04-00', '2011-10-00', 600000, 1),
('1980-09-00', '2010-10-00', 298010, 1),
('1981-05-00', '2040-10-00', 298010, 2),
('2010-11-00', '2029-09-00', 298010, 3);
I need to check whether my DI_Debt_nbr are overlapping or not for each DI_Debt_nbr,
>> at this moment we are checking each row in loop and using function
exec @Overlap1=[DffMonths] @IttermsLD, @ITtermsNextFD;
exec @Overlap2=[DffMonths] @IttermsFD, @ITtermsNextFD;
exec @Overlap3=[DffMonths] @IttermsFD, @ITtermsNextLD; <<
And you were too rude to post the code for these functions! You write SQL with assembly language flags! We do not do that! We also would use a CASE expression, and not IF-THEN control flow in SQL.
Did you know that ANSI/ISO Standard SQL has a temporal <overlaps predicate>? Notice the code to handle NULLs and the ISO half-open interval model.
(start_date_1 > start_date_2
AND NOT (start_date_1 >= end_date_2
AND end_date_1 >= end_date_2))
OR (start_date_2 > start_date_1
AND NOT (start_date_2 >= end_date_1
AND end_date_2 >= end_date_1))
OR (start_date_1 = start_date_2
AND (end_date_1 <> end_date_2 OR end_date_1 = end_date_2))
I tend to prefer the use of a calendar table. NULLs return an empty set, as above.
EXISTS
((SELECT cal_date FROM Calendar
WHERE cal_date BETWEEN start_date_1 AND end_date_1)
INTERSECT
(SELECT cal_date FROM Calendar
WHERE cal_date BETWEEN start_date_2 AND end_date_2))
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Pie graph slice derivation returning two rows
Hi All,
I have a requirement to derive the series name when the user clicks on a pie graph's series.
Below is my pie graphs code
<dvt:pieGraph id="pieGraph1"
value="#{bindings.DashboardTransPieVO1.graphModel}"
subType="PIE" threeDEffect="true"
animationOnDisplay="auto"
seriesRolloverBehavior="RB_HIGHLIGHT"
dynamicResize="DYNAMIC_SIZE" style="Default"
partialTriggers="::cil2"
clickListener="#{viewScope.DashboardScreenBean.drillPie}"
drillingEnabled="true">
<dvt:background>
<dvt:specialEffects/>
</dvt:background>
<dvt:graphPieFrame/>
<dvt:seriesSet>
<dvt:series/>
</dvt:seriesSet>
<dvt:legendTitle text="#{ethuiBundle.TRANSACTION_STATES}"
rendered="true"/>
<dvt:graphFootnote text="Footnote" rendered="false"/>
<dvt:sliceLabel>
<dvt:numberFormat numberType="NUMTYPE_GENERAL"
decimalDigit="0"/>
</dvt:sliceLabel>
<dvt:pieLabel rendered="false"/>
<dvt:graphSubtitle text="Subtitle" rendered="false"/>
<dvt:graphTitle text="Title" rendered="false"/>
</dvt:pieGraph>
I am using following code for that in clickListener of pie graph:
ComponentHandle handle = clickEvent.getComponentHandle();
if (handle instanceof DataComponentHandle)
DataComponentHandle dhandle = (DataComponentHandle)handle;
// Get the value displayed in the series
System.out.println(" @@@@Value: " + dhandle.getValue(DataComponentHandle.UNFORMATTED_VALUE));
// Get the series attributes
Attributes [] seriesInfo = dhandle.getSeriesAttributes();
if(seriesInfo != null)
for(Attributes attrs: seriesInfo)
System.out.println(" @@@@Series value: " + attrs.getValue(Attributes.LABEL_VALUE));
System.out.println(" @@@@Series name: " + attrs.getValue(Attributes.LABEL_ATTRIBUTE));
System.out.println(" @@@@Series value id: " + attrs.getValue(Attributes.ID_VALUE));
System.out.println(" @@@@Series name id: " + attrs.getValue(Attributes.ID_ATTRIBUTE));
The issue is it is returning me two rows for Attributes array. The first row is containing nulls in Attributes array with the exception of ID value and ID Attribute. They carry some standard value like 0 and some text respectively for them.
The 2nd row contains the data I am looking for.
My query is why two rows are being returned?
ThanksCheck this code:
REPORT ytest_pie.
DATA: BEGIN OF data OCCURS 1,
text(36),
feld1 TYPE p,
END OF data,
BEGIN OF opts OCCURS 1,
c(80) TYPE c,
END OF opts,
BEGIN OF tyear OCCURS 1,
c(20) TYPE c,
END OF tyear.
opts-c = 'P2TYPE = PI'.
APPEND opts.
data-text = 'X 10'.
data-feld1 = '10'.
APPEND data.
data-text = 'Y 20'.
data-feld1 = '20'.
APPEND data.
CALL FUNCTION 'GRAPH_MATRIX_2D'
TABLES
data = data
opts = opts
tcol = tyear
EXCEPTIONS
col_invalid = 1
opt_invalid = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
How to make a table control header become two rows?
Hi, all.
May I know how to make the static header/label rown in table control on screen become two rows?
As we know, normally a table control's first row is header, and starting from the second row onwards are it's content or data. So, now I would like to make the hedear/label become first two rows.
Anyone know about it?
Thanks in advance.Hai Lim,
Kindly search in SDN.
"You can't actually have two lines but you can create a title which you may be able to align with the headings to achieve what you want. On the table control tick the 'w/title' box. It then forces you to put an element into a line at the top of the table control."
Regards,
Harish -
I would like the row color to alternate in pairs - for example, two rows of grey then two rows of white. How do I achieve this format?
Hi OldRailroadMan,
Here is one way. Start with a table with no fill (or white).
Change the fill of the first two rows.
Select cells in the first four rows.
Drag the yellow Fill Handle down.
For some reason this does not work if you select whole rows (by clicking on the row numbers at the left).
When you are happy with the result, Menu > File > Save As Template.
Regards,
Ian. -
Display last two rows for every group
Hi,
I want to display only last 2 rows for every group.
My table look like
ACN DATE COST APPL
A6ERA 14-JUN 150 B777
A6ERA 14-JUN 180 B787
A6ERA 15-JUN 120 B677
A6ERA 14-JUN 155 B777
A6ERB 13-JUN 166 A777
A6ERB 14-JUN 157 B777
A6ERB 11-JUN 159 B787
A6ERC 14-JUN 099 B777
A6ERC 11-JUN 102 B788
In the above table, I want to display only the last two rows group by ACN
Like the below table
ACN DATE COST APPL
A6ERA 15-JUN 120 B677
A6ERA 14-JUN 155 B777
A6ERB 14-JUN 157 B777
A6ERB 11-JUN 159 B787
A6ERC 14-JUN 099 B777
A6ERC 11-JUN 102 B788
Please replyNihar
To get the first two rows from each group, you could do this:
Use the ROW_NUMBER() analytic function (see http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions137.htm#i86310)
Now, your question isn't clear what you mean by "last" two rows. Last in what order? Whatever it is, you can use the ORDER BY part of the ROW_NUMBER() function to specify the ordering, and reverse it using DESC - for example:
select acn, adate, cost, appl from (
select acn, adate, cost, appl,
row_number() over (partition by acn order by adate desc) as rn
from acntab
where rn <= 2
order by acn, rnHTH
Regards Nigel
Maybe you are looking for
-
Error while invoking onHeartBeat() method, exception is "Cannot load header
I have a problem that when I read out an IMAP mailbox I sometimes get the above problem, and sometimes I don't get the problem. Below I attached the main parts of my environment to get an insight within the code: bpel.xml of process that is reading o
-
Beginner can't undeploy auto-deployed web app
Hi. (I am brand new to WLS 10. I am testing it for a possible upgrade from WLS 8.) I auto-deployed a web application Weblogic Server 10.0. Now I am trying to undeploy it, but I just can't seem to make it go away. I first tried the delete button in th
-
Cannot unlock my Admin account, updaters fail, more...
After installing SL, I can no longer unlock my Admin account. When I click the lock to make changes, it says "Authenticating..." for a second, then stays locked. When trying to update applications (I've tried several), the "Install" button dims for a
-
Unless it's already possible, anybody know if Apple ever plans on updating "Address Book" to enable the user to password protect an address book and to have multiple address books.... Having multiple sign-ins is not really a solution. Thx MBP 2ghz 1g
-
Script to turn Airport on at start up
computers MacBook 2GHz Intel OS 10.4.11 We authenticate to an open directory server. If a student turns the airport off before he shuts down the next student can not login. An administator has to login locally and turn the airport back on before the