How to find the closest higher value?
Hi allI want to select the closest higher value in my data (test data are below):
with test_data as
( select 0.21 as val1, 0.19 as val2 from dual
union all
select 0.21 as val1, 0.29 as val2 from dual
union all
select 0.21 as val1, 0.49 as val2 from dual
union all
select 0.67 as val1, 0.49 as val2 from dual
union all
select 0.67 as val1, 0.69 as val2 from dual
)
select * from
(
select
val1,
val2,
rank() over (order by abs(val2 - val1)) nearest
from test_data
)
where nearest = 1;
output:VAL1 VAL2 NEAREST
0.21 0.19 1
0.67 0.69 1
Output of this query is the NEAREST value to the value in the column of VAL1. But I would get the SUPERIOR value CLOSEST. As below the value at the higher value 0.21 closest isn't 0.29 0.19.desired output:
VAL1 VAL2
0.21 0.29
0.67 0.69
Is it possible to get the features you want using analytical functions?Thx for the help!
Kind regards
Jiri
Published by: Jiri n. 10 October 2012 01:14
with test_data as
( select 0.21 as val1, 0.19 as val2 from dual
union all
select 0.21 as val1, 0.29 as val2 from dual
union all
select 0.21 as val1, 0.49 as val2 from dual
union all
select 0.67 as val1, 0.49 as val2 from dual
union all
select 0.67 as val1, 0.69 as val2 from dual
)
select
val1
,val2
,first_value(val2) over (partition by val1 order by
case when val2 >= val1 then 1 else 2 end
, val2
) nearest
from test_data
VAL1 VAL2 NEAREST
.21 .29 .29
.21 .49 .29
.21 .19 .29
.67 .69 .69
.67 .49 .69
Tags: Database
Similar Questions
-
How to find the first max value for each item
Hello
I have the me_result of the table as below,
SELECT * FROM me_result;
ID ||| ELITE ||||||||||| FREQ_ITEM | COMBINED_STR | SUP
1 ||; 1; 10; 2; 3; 4; 5; 7; 8. 1 ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
2 ||; 1; 10; 2; 3; 4; 5; 7; 8. 2 ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
3 ||; 1; 10; 2; 3; 4; 5; 7; 8. 3 ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
4 ||; 1; 10; 2; 3; 4; 5; 7; 8. 4 ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
5 ||; 1; 10; 2; 3; 4; 5; 7; 8. 5 ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
6 ||; 10; 2; 3; 4; 5; 8; 9. 1 ||||||||||||||; 10; 2; 3; 4; 5; 8; 9; 1 ||| 1
7 ||; 10; 2; 3; 4; 5; 8; 9. 2 ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2
8 ||; 10; 2; 3; 4; 5; 8; 9. 3 ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2
9 ||; 10; 2; 3; 4; 5; 8; 9. 4 ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2
10 ||; 10; 2; 3; 4; 5; 8; 9. 5 ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2
I need to find the first COMBINED_STR max for each element of the ELITE,
I mean, max value is the max REGEXP_COUNT (combined_str,' ;')))
really, I try to write down, but I had a lot of values for each ELITE and I need only the first, that
SELECT * from me_result
WHERE (ELITE, REGEXP_COUNT (combined_str,' ;')))) IN
(SELECT ELITE, MAX (REGEXP_COUNT (combined_str,' ;'))))) ME_RESULT ELITE GROUP);
I need the result to be as below.
1; 1; 10; 2; 3; 4; 5; 7; 8-1; 1; 10; 2; 3; 4; 5; 7; : p
6; 10; 2; 3; 4; 5; 8; 9 1; 10; 2; 3; 4; 5; 8; 9; 1 1
any help please,.
Published by: user11309581 on July 10, 2011 22:03Can be
with t as (select 1 ID, ';1;10;2;3;4;5;7;8' ELITE, 1 FREQ_ITEM, ';1;10;2;3;4;5;7;8' COMBINED_STR, 2 SUP from dual union all select 2 ,';1;10;2;3;4;5;7;8' ,2 ,';1;10;2;3;4;5;7;8' ,2 from dual union all select 3 ,';1;10;2;3;4;5;7;8' ,3 ,';1;10;2;3;4;5;7;8' ,2 from dual union all select 4 ,';1;10;2;3;4;5;7;8' ,4 ,';1;10;2;3;4;5;7;8' ,2 from dual union all select 5 ,';1;10;2;3;4;5;7;8' ,5 ,';1;10;2;3;4;5;7;8' ,2 from dual union all select 6 ,';10;2;3;4;5;8;9' ,1 ,';10;2;3;4;5;8;9;1' ,1 from dual union all select 7 ,';10;2;3;4;5;8;9' ,2 ,';10;2;3;4;5;8;9' ,2 from dual union all select 8 ,';10;2;3;4;5;8;9' ,3 ,';10;2;3;4;5;8;9' ,2 from dual union all select 9 ,';10;2;3;4;5;8;9' ,4 ,';10;2;3;4;5;8;9' ,2 from dual union all select 10 ,';10;2;3;4;5;8;9' ,5 ,';10;2;3;4;5;8;9' ,2 from dual ) select ID,ELITE,FREQ_ITEM,COMBINED_STR,SUP from ( SELECT ID,ELITE,FREQ_ITEM,COMBINED_STR,SUP, ROW_NUMBER() over (PARTITION BY ELITE order by id) RN FROM t WHERE (ELITE,REGEXP_COUNT(combined_str,';')) IN (SELECT ELITE,MAX(REGEXP_COUNT(combined_str,';')) FROM t GROUP BY ELITE) ) where RN=1 order by id ID ELITE FREQ_ITEM COMBINED_STR SUP ---------------------- ----------------- ---------------------- ----------------- ---------------------- 1 ;1;10;2;3;4;5;7;8 1 ;1;10;2;3;4;5;7;8 2 6 ;10;2;3;4;5;8;9 1 ;10;2;3;4;5;8;9;1 1
-
How to find the value max and min for each column in a table 2d?
How to find the value max and min for each column in a table 2d?
For example, in the table max/min for the first three columns would be 45/23, 14/10, 80/67.
Thank you
Chuck,
With color on your bars, you should have enough experience to understand this.
You're a loop in the table already. Now you just need a function like table Max and min. loop. And you may need to transpose the table 2D.
-
How to find the Web sites of high quality backlinks?
Original title: how to find quality backlinks?
Updates on the algorithms research of new google forward a site spammy that build a bad backlinks. But how to find the Web sites of high quality backlinks? Could we must spend a lot of money to get their links?
Please help me.I want to increase backlinks to my site
Hello
I recommend you contact Google support for assistance:
http://support.Google.com/bin/static.py?hl=en&page=portal_groups.cs
Hope the helps of information.
-
How to find the value dated the same day in the last year
I want to know how to find the value dated the same day in the last year.
I use now, there is the function with the year and the result is
Year Rev There are Rev 2011 3000 2012 4000 3000 2013 2000 4000 2014 5000 2000 It works but it's not that I want. I'm trying to add the column date (Ex.20140101) in my report but it'snot work.
I want to show:
Date Rev There are Rev 20110112 200 20120112 100 200 20130112 300 100 20140112 500 300 If use (< degree >, < time_dim >. < date >, 365), it works but does not correct 100%
Please help me...
Thank you very much
Check this link cool - bi.com
-
How to find the bpel instance in 11 g based on the index values
We have 10 GB BPEL processes where we define the 4 index values for all instances. Whenever the support request comes, ask us the values of index and based on what we're looking for the process instance.
We have now migrated bpel 10g and 11g process. How to find the bpel instance in 11 g based on the index values?You can go there. http://soasphere.blogspot.com/2011/04/how-to-Serch-composites-for-index.html. Do a join on the cube_instance and ci_indexes tables.
-
How to find the max value of scrollV in AS3?
I used the response from Ned to get my 3 fields of scrolling text set based on the value of one of them. Thanks Ned!
The other two text fields scroll to match the text box 'parent', but in the end – you get to the last scroll position - the other two do not update and 3 text fields are out of alignment. It's just at the end of the roll. The rest of the scroll values line up. I think that if I can find the scrollV max value, I can force the two others to scroll one last time when this value is reached by the text field "parent".
The textfield object has a property for this: maxScrollV.
-
How to find the number of data items in a file written with the ArryToFile function?
I wrote a table of number in 2 groups of columns in a file using LabWindows/CVI ArrayToFile... Now, if I want to read the file with the FileToArray function so how do I know the number of items in the file. during the time of writing, I know how many elements array to write. But assume that I want the file to be read at a later time, then how to find the number of items in the file, so that I can read the exact number and present it. Thank you all
Hello
I start with the second question:
bytes_read = ReadLine (file_handle, line_buffer, maximum_bytes);
the second argument is the buffer to store the characters read, so it's an array of characters; It must be large enough to hold maximum_bytes the value NULL, if char [maximum_butes + 1]
So, obviously the number of lines in your text tiles can be determined in a loop:
Open the file
lines = 0;
While (ReadLine () > 0)
{
lines ++;
}
Close the file
-
Hi Member
I have download the LabVIEW Machine https://decibel.ni.com/content/docs/DOC-19328 learning package
I want to run the K average algorithm to group the image in a group of two or three or more
the problem is how to find the result I mean the image of clustred', the image that contain 2 or three threatened value only
or how aasign a 1 value for all the intesity who
belong to the cluster a and 255 for data that belongs to group 2
for the look of the image as binary image?
a my vi below
Best regards
my post before shows how to set the threshold manually using the slider of the graph.
Here is the version k-means automated help .vi box tools
Alex
-
How to find the snid? If it is removed or deleted from this sticker on the back?
How to find the snid and sn & id of the laptop if it is removed or deleted this sticker on the back?
My laptop is acer ferrari 1000
Tools Information as SIW system reports the product name and serial number IF this information is stored somewhere in the computer.
I don't know what you mean by 'id', but for example, all the following values are reported by SIW:
Manufacturer
Name of the product
Version
Serial number
Type of machine
Infrared (IR) supported
DMI system UUID
UUID -
How to change the number of values in the hour that are restricted.
Hello
May I know how to change the number of values in the hour that are restricted.
In fact, we have improved of obiee in obiee 11g 10g. Data base is the same for Both.In 10 g the prompt value is limited to show only 35 records per page. As we passed it shows only 35 Records in 11g also. How can I change this limit to 11g.
Please suggest me! Its urgent!
Thanks and greetings
Navnitha
Hello
In the advance tab we have the XML of the upgraded report, copy it into a Notepad and try to find the line beginning as below
In 10g, we have something like below, simply remove the choicesPerPage = '35' from 11 g OBIEE XML report
Thank you
RAM
-
How to find the Bookmarks panel is enable or disable the use of Applescript?
Hi all
In Indesign, how to find the Bookmarks panel is enable or disable the use of applescript?
Please any idea on this subject!
Thank you
John.
Hi John,.
Version CC 2015 (and I guess in earlier versions) you would use:
Tell application "Adobe InDesign CC 2015"
the visible isVisible value of "Bookmarks" Panel
tell the end
isVisible
-
How to find the dynamic inside the af acomponent ID: foreach?
Hi friends,
Jdev: 11.1.1.7
I have a requirement like I need a list of books available as links. So I posted using af: foreach and inside I used af:goLink.
I need to display the ToolTip on mouseover this link. To display the ToolTip, I used the popup. How to find the dynamic ID inside the af: foreach in java.
If I bind the comonent, it does not work inside foreach.
Try this way, root.findComponent("r1:it2"); it is in taskflow. On popufetchlistener you call a method to get the id of the component to get the book desc.
Thank you
Hello
You can probably assign a customer attribute for elements and then using that you could get the values?
Check out https://docs.oracle.com/cd/E21764_01/apirefs.1111/e12419/tagdoc/af_clientAttribute.html and http://jdevadf.oracle.com/adf-richclient-demo/faces/components/clientAttribute.jspx
Arun-
-
How to find the age of a child and snapshot number snapshot for a virtual machine.
Hi all
How to find the age of a snapshot for a virtual machine child count and snapshot.
This code snippet should help... Assuming that you have the following entries:
VM (VC:VirtualMachine)
snapshot (VC:VirtualMachineSnapshot)
System.log("====== Snapshot details for VM: "+snapshot.config.name+" ======"); var snapshotTrees = vm.snapshot.rootSnapshotList; System.log("Snapshot Tree Count: "+snapshotTrees.length); for each (snapshotTree in snapshotTrees){ showSnapshotInfo(snapshotTree, snapshot); } function showSnapshotInfo(snapshotTree, selectedSnapshot){ if(selectedSnapshot == snapshotTree.snapshot){ System.log("===================="); System.log("Name: "+snapshotTree.name); System.log("Id: "+snapshotTree.id); System.log("Description: "+snapshotTree.description); System.log("createTime: "+snapshotTree.createTime); System.log("quiesced: "+snapshotTree.quiesced); System.log("replaySupported: "+snapshotTree.replaySupported); System.log("backupManifest: "+snapshotTree.backupManifest); System.log("snapshot id: "+snapshotTree.snapshot.id); System.log("state: "+snapshotTree.state.value); var childSnapshotList = snapshotTree.childSnapshotList; if(childSnapshotList != null){ System.log("childSnapshotList length: "+snapshotTree.childSnapshotList.length); } System.log(""); } if(snapshotTree.childSnapshotList != null){ System.log("Children found: "+snapshotTree.childSnapshotList.length); for each (childSnapshotTree in snapshotTree.childSnapshotList){ showSnapshotInfo(childSnapshotTree, selectedSnapshot); } } }
During the passage of one of my virtual machines, here is an example of output I get:
[2014-06-12 15:19:21.493] [I] Snapshot Tree Count: 1 [2014-06-12 15:19:21.493] [I] ==================== [2014-06-12 15:19:21.494] [I] Name: before upgrade to 5.0.1 [2014-06-12 15:19:21.494] [I] Id: 31 [2014-06-12 15:19:21.494] [I] Description: [2014-06-12 15:19:21.495] [I] createTime: Mon Mar 19 2012 13:48:57 GMT-0400 (EDT) [2014-06-12 15:19:21.495] [I] quiesced: false [2014-06-12 15:19:21.495] [I] replaySupported: null [2014-06-12 15:19:21.495] [I] backupManifest: null [2014-06-12 15:19:21.496] [I] snapshot id: snapshot-83 [2014-06-12 15:19:21.496] [I] state: poweredOff [2014-06-12 15:19:21.496] [I] childSnapshotList length: 1 [2014-06-12 15:19:21.496] [I] [2014-06-12 15:19:21.497] [I] ==================== [2014-06-12 15:19:21.497] [I] Name: Before 5.1 upgrade [2014-06-12 15:19:21.497] [I] Id: 36 [2014-06-12 15:19:21.497] [I] Description: [2014-06-12 15:19:21.498] [I] createTime: Fri Sep 21 2012 21:59:58 GMT-0400 (EDT) [2014-06-12 15:19:21.498] [I] quiesced: false [2014-06-12 15:19:21.498] [I] replaySupported: null [2014-06-12 15:19:21.498] [I] backupManifest: null [2014-06-12 15:19:21.499] [I] snapshot id: snapshot-84 [2014-06-12 15:19:21.499] [I] state: poweredOff [2014-06-12 15:19:21.499] [I] childSnapshotList length: 1 [2014-06-12 15:19:21.499] [I] [2014-06-12 15:19:21.500] [I] ==================== [2014-06-12 15:19:21.500] [I] Name: Before Named Instance [2014-06-12 15:19:21.500] [I] Id: 37 [2014-06-12 15:19:21.501] [I] Description: [2014-06-12 15:19:21.501] [I] createTime: Mon Nov 11 2013 13:40:46 GMT-0500 (EST) [2014-06-12 15:19:21.501] [I] quiesced: false [2014-06-12 15:19:21.501] [I] replaySupported: null [2014-06-12 15:19:21.502] [I] backupManifest: null [2014-06-12 15:19:21.502] [I] snapshot id: snapshot-236 [2014-06-12 15:19:21.502] [I] state: poweredOff [2014-06-12 15:19:21.502] [I]
-
How to find the password for the embedded weblogic Server
How to find the password for the server weblogic shipped from jdeveloper please?
User, please tell us our jdev version!
You can't find. Once he lost you can set a new one. For this you can either remove server embedded weblogic (delete the DefaultDomain file in the folder system11.1.1.x.x.x.x.) either you go to the system11.1.1x.xx.x/DefaultDomain/servers/DefaultServer/security folder and open the file boot.properties and delete the encrypted user name and password values and enter the new values for them in normal character. Save the file and restart the integrated server. Connection with the new username and password and it should work.
The new user name and password are encrypted automatically.
Timo
Maybe you are looking for
-
Satellite A300 - his stutters when I enable Wi - FI turns
Hello! I am owner of a Satellite A300, and almost from the beginning, I noticed some occasional stuttering on the sound. Really got me bugged with this question, and I tried several times to solve. I even got to the point of resetting the default com
-
My calculator function disappeared. How can I get that back?
When I go to help and support the only anwser I get "using Calculator" However, when I click on the section of underlined calculator that is the answer cannot be found.
-
Pavilion dv4-1225dx Notebook: pavilion dv4-1225dx code mobile phone
Dear all, My laptop has lent to my sister in law. Tried to use it after his return there less power cord which I had to buy. His grandson stupid terror has changed my password and password indication contains derogatory words that I can't repeat. A
-
I ended the process windows exploror and changed my theme
I tried to restart the computer 2 times and the process runs again, but I have a kind of classic theme now and can not change, I went to advanced tools > adjust the appearance and performance of windows, visual affects and tried to check the lower bo
-
How to add music to the screen saver?
need to add music