an analytic function can be used to get the next largest value?
I have a table with the values as follows:ID term val
1 200720 aaa
1 200720 bbb
1 200720 ccc
1 201220 ddd
1 201220 eee
2 200720 qqq
2 200720 rrr
2 200920 sss
What I need, is to get the value of the next higher period (999999 if not exist) for each id line, like this:
ID term val next_term
1 200720 aaa 201220
1 200720 bbb 201220
1 200720 ccc 201220
1 201220 ddd 999999
1 eee 201220 999999
2 200720 qqq 200920
2 200720 rrr 200920
2 200920 sss 999999
I tried lead futures partitiion by id, but that just gives me the value in the next line. I watched windowing, but my eyes crossed. Any ideas? I need the next highest value not the value in the next line. The value of next_term must never be identical to the value term
CREATE TABLE WJPTEST
(
ID VARCHAR2 (3 CHAR),
VARCHAR2 (6 CHAR) TERM,
VAL VARCHAR2 (3 CHAR)
)
;
Insert into WJPTEST
(ID, VAL)
Values
('1', '200720', 'aaa');
Insert into WJPTEST
(ID, VAL)
Values
('1', '200720', 'bbb');
Insert into WJPTEST
(ID, VAL)
Values
('1', '200720', 'ccc');
Insert into WJPTEST
(ID, VAL)
Values
('1', ' 201220 ","ddd");
Insert into WJPTEST
(ID, VAL)
Values
('1', ' 201220 ","eee");
Insert into WJPTEST
(ID, VAL)
Values
('2', '200720', 'qqq');
Insert into WJPTEST
(ID, VAL)
Values
('2', '200720', 'rrr');
Insert into WJPTEST
(ID, VAL)
Values
('2', '200920', 'sss');
COMMIT;
Published by: wjpenfold on 12 June 2012 10:08
wjpenfold wrote:
what I want is the next largest value that may never be the same value as the current line. I'm working on getting the code example.
What are the increments of TEMP? Assuming that the TERM cannot grow less than 1:
NVL (Lead (term) OVER (PARTITION BY id ORDER BY term RANK BETWEEN 1 NEXT AND UNBOUNDED FOLLOWING), 999999)
For example:
select sal,
NVL(FIRST_VALUE(sal) OVER (ORDER BY sal RANGE BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING),999999) lead_sal
from emp
order by sal
/
SAL LEAD_SAL
---------- ----------
800 950
950 1100
1100 1250
1250 1300
1250 1300
1300 1500
1500 1600
1600 2450
SAL LEAD_SAL
---------- ----------
2450 2850
2850 2975
2975 3000
3000 5000
3000 5000
5000 999999
14 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
Any idea which function Essbase or a combination of function can be used to get the level zero members of a list of members. I know that @RELATIVE or @DESCENDANTS cannot be used.
If you want to fix on all level 0 members in a member set, then maybe @ILDESCENDANTS will work for you. Something like: @ILDESCENDANTS (@LIST (members), 0)
-
Order WMI - what command can I use to get the temperature of the GPU?
Which command can I use to get the temperature of the GPU in WMI?
Hi Daniel_99,
· Do you use some kind of scripts?
Your Windows XP question is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public. Please post your question in the TechNet Windows XP forum.
http://social.technet.Microsoft.com/forums/en-us/category/windowsxpitpro
I hope this helps.
-
EXTRACT function can be used directly in the CASE statement WHEN
I wrote the following SELECT statement. The function 'calc_time_diff' is a stored function that subtracts two timestamps and returns the result to the total number of seconds. My DBA does not 'calc_time_diff' as a stored function, then, I replaced the third line (in bold) in the SELECT statement with this:
COUNTY ( BOX WHEN (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +)
(extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.
(excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.
extract ((DEUXIÈME à PARTIR de v_end_ts-v_st_ts) < 3600 THEN 1 END) less_than_1_hrs_count
But the CASE above does not work. It returns the same value as COUNT (*). If the total number of tickets is 32 output will be
total_tickets less_than_1_hrs_count
32 32
If I call the "calc_time_diff" then I get the correct result. What I'm doing wrong here?
**********************************************************************************************************************************************************************
SELECT
Count (*) total_tickets,
COUNTY ( CASE WHEN END of calc_time_diff (t.created_date, h.closed_date) < 3600 THEN 1) less_than_1_hrs_count
OF n01.cc_ticket_info t
JOIN IN-HOUSE
(SELECT ticket_id, MAX (created_date) closed_date
OF n01.cc_ticket_status_history
WHERE ticket_status = 'CLOSED' AND created_date > = 18 August 2013 ' AND created_date < (to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY)
GROUP BY ticket_id
) h
WE (t.ticket_id = h.ticket_id)
INNER JOIN n01.cc_ticket_notes n
WE (n.created_date = h.closed_date)
WHERE (t. ticket_status = 'NOTIFICATION' t.ticket_status 'CLOSED' = GOLD) AND t.created_date > = 18 August 2013 ' AND t.last_changed < to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY);
***********************************************************************************************************************************************************
create or replace
FUNCTION calc_time_diff)
p_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %,
p_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %)
RETURN NUMBER
AS
v_no_sec NUMBER;
v_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %;
v_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %;
BEGIN
v_st_ts: = p_st_ts;
v_end_ts: = p_end_ts;
SELECT (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +.
(extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.
(excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.
excerpt ((SECOND from v_end_ts-v_st_ts)
IN v_no_sec
DOUBLE;
Return v_no_sec;
END calc_time_diff;
Hello
You don't need a function defined by the user or the EXTRACT to find the difference between two timestamps.
SELECT COUNT (*) AS total_tickets
, COUNTY ( BOX WHEN h.closed_date < t.created_date="" +="" interval="" '1'=""> )
THEN 1
END
) AS less_than_1_hrs_count
...
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
Pc tune up utility can I use to get the most out of my pc.
I had avg pc tune up.
now m using tuneup utilities.
want a better.Hello
It is best that you do not use utilities to tune-up, because these applications may incorrectly delete important files and entries that can leave your computer in the absence of priming.
You can use the tools that are built into Windows, to increase the performance of the computer.Link to view:
Slow PC? Optimize your computer for peak performance
http://www.Microsoft.com/athome/Setup/optimize.aspxHope this information is useful.
-
Android-BB version IPA from Google who purchases can I use to get the correct answer?
Hello
I packed up our Android app to use on the Playbook and everything works. The only problem is with in the purchases, he said.
For in app purchase I've supported on the verification of the signatures of SKU and transaction.
To test, I followed this instruction
http://supportforums.BlackBerry.com/T5/Android-runtime-development/PlayBook-Beta-2-1-in-app-payments...I can download the app but its not answered. In-app purchase does not work.
At the same station, few people said that Google IPA V3.0 does not work. We use Google API V3.0 in fact, Google has published IAP V5.0 we are in the process of integration that.
I want to know which Google IPA versions works perfectly fine with BB, I can see V3 and V5 are not working. So should I try with V2, in fact Google has deprecated code V2, so just wanted confirmation of any developer of BB on the version of the IAP, what version should be used?
Thank you!
AdelineHello Olivier,.
You can use v2. Version 3 uses the SDK to play from Google that is not supported.
For additional questions on payments app, see our documentation at: https://developer.blackberry.com/android/apisupport/apisupport_inapp_payments_support.html
See you soon,.
Matt
-
After the activation of phone can I use same key the next reformat windows 7
Hello I have key for windows 7, the last time I activated by phone from your key is expired I will format my hard drive can and activate my product for the same key
Yes, but you may need to use the activation of the phone again.
I suggest that you create a backup of your installation of Windows 7 activated now, so when you want to format your computer, just restore the backup facility:
http://www.notebooks.com/2009/10/24/how-to-backup-your-installation-of-Windows-7/
-
My laptop stopped recognizing wireless function. What drop-down list function should I use to get it to recognize wireless again?
Hello
What is the brand and model of your laptop?
Follow the suggestions and check out them.
Method 1
You can follow the procedure in the article.
Enable or disable a network adapter
http://Windows.Microsoft.com/en-us/Windows-Vista/enable-or-disable-a-network-adapter
Method 2
Windows wireless and wired network connection problems
See also:
Network adapter problems
http://Windows.Microsoft.com/en-us/Windows-Vista/troubleshoot-network-adapter-problems
-
In my laptop, when I open the itunes window there is an option 'Internet Radio' to listen to the different type of music. This "Internet Radio" function can be used on my iphone 5? And if so, how can I make it work?
No more. It merged with the Apple's music.
-
Case function can be used as a parameter when calling a procedure, please notify
The daily procedure is called with the parameter 3 following one of the parameters using a function box between them as shown below.
Daily_Ins (c1.p_mtrid, c1.p_UOM CASE WHEN "KWH" THEN 1 ELSIF 'KW' THEN 2 END, v_dateHold);
In my opinion, using decode is illegal, so I think that I cannot say something like :
Daily_Ins (c1.p_mtrid, ( decode c1.p_UOM, "KWH", 1 'KW', 2), v_dateHold);
I think I just found something on the net
SQL > DECLARE
2 wages NUMBER: = 20000;
3 employee_id NUMBER: 36325 =;
4
5 PROCEDURE give_bonus (emp_id in NUMBER, bonus_amt number) IS
6 BEGIN
7 DBMS_OUTPUT. Put_line (emp_id);
8 DBMS_OUTPUT. Put_line (bonus_amt);
9 END;
10
BEGIN 11
12 give_bonus (employe_id,
13 CASES
14 salary when > = 10000 AND salary<=20000 then="">=20000>
15. WHAT salary > 20000 AND salary<= 40000="" then="">=>
16. WHAT > 40000 salary THEN 500
17 0 OTHERWISE
18 END);
END 19;
20.
PL/SQL procedure successfully completed.
-
If we then use the DML in function, this function can be used inside s
If we use the DML statement in a function, then this function can be used within the select query or any DML query?select f from t2;
I think that you wanted to interrogate t1.
This works if the function is a stand-alone transaction:
create or replace function f return number is PRAGMA AUTONOMOUS_TRANSACTION; begin update t1 set c=2; commit; return 1; end; / select f from t1
But as Billy, why would you do this way DML. And it's not stand-alone procedures should be used.
A response to an interview question, but nothing wrong with it.
-
Windows Easy Transfer of 64-bit to 32-bit, or vice versa
HelloI'm trying to fix my settings my current machien to a W7 VM user to make sure that I have the transfer settings and I get all the information I want. My machine is 64 bit, but the VM is 32-bit. I can't seem to get the easy transfer Windows from Windows Vista to play with Windows 7 easy transfer and can't seem to install the transfer Windows 7 because it gives me only a 32-bit version to install...
How I have a 64-bit Windows 7 Easy Transfer to install and if I get one to install and build a transfer saved the data file has there 'restore' on a 32-bit Windows?
George George P Botuwell, programmer
Hi George P Boutwell,.
Thank you for using answers Forum.
I think that VMware has a 64-bit/function version. You will need to contact them to verify this.
64-bit to 32-bit is not supported by Windows Easy Transfer, as far as I know.I hope this helps.
Chris
Microsoft Answers Support Engineer
Visit our Microsoft answers feedback Forum and let us know what you think. -
Try to use ePrint, get the message "Please wait HP Print complete previous jobs.
Printer photosmart = 5510
Conputer laptop computer = HP Pavilion
OS = Windows 8.1
Try to use ePrint, get the message 'Please wait while HP Print complete previous jobs' status is displayed 1 point with zero page. Green bar keeps scrolliong in the top of the window. Tried to cancel this job without success. Someone at - it ideas? In my view, that the "previous work" was sent to ePrint before mobile computer account registration has been made.
Hi @jhaiar ,
I understand that you are a problem with ePrint and your Photosmart 5510. I want to help you with this.
One option is to remove web services, and then turn it back on. Unfortunately if you have customized the ePrint address, you will never lose it. You can always create a new address, it cannot just be old.
HP has a support group of service based for Cloud related issues. This means no warranty or support costs.
If you do not want to remove the web services, give them a call. They might have another option.
Please contact our Cloud Services at 855-785-2777. If you do not live in the United States / Canada region, please click the link below to get help from your region number. http://WWW8.HP.com/us/en/contact-HP/WW-phone-assist.html
-
AD can be used to configure the registry?
Active directory can be used to configure the registry? My understanding is that only local security settings can be configured using Group Policy in the ad. I've always written scripts of security in order to harden the registry. Please adise, thank you
This issue is beyond the scope of this site (for consumers) and to be sure, you get the best (and fastest) reply, we have to ask either on Technet (for IT Pro) or MSDN (for developers)
If you give us a link to the new thread we can point to some resources it -
I'm trying to uninstall Verizon's VZ Access Manager. I get "invalid UNINSTALL Uninstall Wise. LOG file. How can I get this off for Verizon can help me to get the new drivers installed?
Hello retabox, welcome.
It would seem that the installer is corrupted. I recommend trying to use the Windows Installer Cleanup utility to force - to remove the application. Try this:1. go to: http://support.microsoft.com/kb/2903012. click on the download link in the middle of the page3. save the file to your desktop or just click Run the installation of the application4. once the application is installed, open the utility. The utility must be located in the menu START under (START > programs > Windows Installer...)5. in the utility, find the application you want to uninstall, and then click the button 'delete' below6. once removed, restart the computer and see if you can reinstall the applicationLet us know if it works,Thank you!Ryan Thieman
Microsoft Answers Support Engineer
Visit our Microsoft answers feedback Forum and let us know what you think.
Maybe you are looking for
-
Huge resolution in the homepage of Facebook and wall. Games not affected, the other tabs do not affected. Works fine in all other browsers. Cannot find any information on the Teas anywhere. Tried to change the Ad block settings, therefore not caused
-
Unable to connect to wireless networking
My Toshiba laptop has been pre-installed with Windows 7 Home premium 64 - bit OS and it worked quite well with the BB wireless. However, the wireless internet was on and turned off in recent weeks, while other mobile devices, such as iphone, ipad, or
-
Several questions on Satellite P855-33N
Hello world.I bought my computer a year ago and since that time, I have a lot of problems. My main problem is with the graphics driver. When I left my computer awhile, my screen becomes darker and never open again. I Force shutdown. Today, I get a me
-
I have a problem whit security for Microsoft Works 8 (KB977304), appear always 646 error Code? Help, please!
-
HP Deskjet 3510: HP Deskjet 3510 - unable to connect to the printer
I had this printer for some time but have never been able to properly print to this printer using this specific computer. FYI, I'm trying to print wireless at it. This office has wireless compatibility. I have the drivers and all (I think, I HP ev