[10g] Simple question on selecting a column in same record as a min value
I have the following sample data to illustrate my question:
CREATE TABLE t_1
( c_a VARCHAR2(1)
, c_b NUMBER(2)
, c_c DATE
INSERT INTO t_1
VALUES('A',1,SYSDATE);
INSERT INTO t_1
VALUES('A',2,SYSDATE+1);
INSERT INTO t_1
VALUES('A',3,SYSDATE+2);
INSERT INTO t_1
VALUES('A',4,SYSDATE+3);
INSERT INTO t_1
VALUES('B',3,SYSDATE+6);
INSERT INTO t_1
VALUES('B',4,SYSDATE+7);
INSERT INTO t_1
VALUES('B',5,SYSDATE+8);I have the following query which allows me to select the value of c_c that corresponds with the minimum value of c_b grouped by c_a. In other words, my goal is: for each value in c_a, I want the value of c_c that corresponds with the minimum value of c_b.
SELECT t1.c_a
, t1.c_c
FROM t_1 t1
SELECT c_a
, MIN(c_b) AS min_c_b
FROM t_1
GROUP BY c_a
) t2
WHERE t1.c_a = t2.c_a
AND t1.c_b = t2.min_c_b
;This query works, but I'm wondering if there is a more efficient way to do this. Something without a subquery? I can't come up with anything else... It just gets a bit ugly with my real data, as there are probably 10 columns of data instead of 3. (Still only 1 minimum value though).
Hi,
Since you're using Oracle 10, you can do this:
SELECT c_a
, MIN (c_c) KEEP (DENSE_RANK FIRST ORDER BY c_b) AS c_of_min_b
FROM t_1
GROUP BY c_a
;This won't work in earlier versions.
What do you want in case of a tie?
For example, if we add one more row to the sample data:
INSERT INTO t_1 (c_a, c_b, c_c)
VALUES ('A', 1, DATE '2001-01-01');Now there are two rows, one dated today and one dated 2001, that have an equal claim to being the "first" in group 'A', since they have the exact same value of c_b.
The query above would display the row from 2001, that is, the earliest of the contenders. That's what MIN means in the query above. Instead of MIN, you can use any aggregate function, but, of course, that function has to work on your data type.
If you want to show all the contenders in case of a tie, then you can stick with your original query, or you could use the analytic RANK function.
WITH got_rnk AS
SELECT c_a, c_c
, RANK () OVER ( PARTITION BY c_a
ORDER BY c_b
) AS rnk
FROM t_1
SELECT c_a, c_c
FROM got_rnk
WHERE rnk = 1
;This approach requires a sub-query, because analytic functions (like RANK) are computed after the WHERE clause is applied. If we want to use the results of an anlytic func tion in a WHERE clause, we have to compute the function in a suib-query first.
Similar Messages
-
Simple Question - attribute alternative text within the same Word doc
ok. I am having a brain freeze and can't locate the answer in the OPA help. Simple question.
Is there a simple way to alias an attribute for use in Word?
For instance the following two conclusions create 2 attributes where I only want 1 attribute.
the annual percentage rate = 6
APR = the annual percentage rate
Is there a configuration option or something to alias APR as the annual percentage rate for use in Word? I want to use either in the same Word document. Something in my head tells me I saw that once before, but all of a sudden I have a brain freeze.
Sorry for such a simple question, but sometimes I get too deep in the weeds.Hi Paul,
You may be thinking of the OPA legend style. In the Office 2007 OPM ribbon it's called Table Legend, but I believe it works with non-table rules in Word as well - it certainly used to.
It's an OPA rule style which can be used when you want to refer to a shorthand version of an attribute, e.g. "APR" instead of "the annual percentage rate". I believe it only applies to the rule immediately below where it has been set in the doc, and not the entire doc.
I did a quick search in the OPM Help and found references to the legend style, but I didn't find a description of the functionality (I didn't search too thoroughly though).
Here basically how it works...
Above the rule write the shorthand version, then the word "is", then the full attribute text, e.g.
APR is the annual percentage rateSide note: I always bold the "is" in the legend line. This is not required, but I like to do it because it makes it clearer at a glance which part is the shorthand and which part is the full attribute text.
Then apply the Table Legend style to the line, then put your Word table or regular rule below it, e.g.
[legend]APR is the annual percentage rate
the result = APR * 10 I use this functionality occasionally. Usually it's when I've got calculations in Word tables and I'm trying to make the left hand column more readable, e.g. using something "APR" in the formula so that it doesn't take up so much space.
Cheers,
Jasmine -
OAM 10g - Simple question (I think)
Hey guys, I want to run something by you to see if I'm missing something critical. What I'm trying to do is fairly simple...
I want 2 login forms for the same webpage, depending on which hostname is used.
internal.mydomain.com
external.mydomain.com
both of these point to an IIS box, which is configured to receive on *:80.. no hostheaders defined.
Originally, there was only the internal.mydomain.com and that is all setup and working. Accessing http://internal.mydomain.com/secret brings up my "Custom Internal Form".
I want to add the ability so that when http://external.mydomain.com/secret is acccessed, it brings up my "Custom External Form".
I have set up a new Host Identifier with external.mydomain.com
I have copied the policy domain to "My Policy - External" and set it to the new Host Identifier, and specified to use Basic Over LDAP (as a quick test, will create the actual form later)
When I access external.mydomain.com/secret I keep getting the "Custom Internal Form".
When I perform an Access Test within oam to the same URL, it shows the correct ("My Policy - External" ) policy domain in the evaluation result, aka.
This tells me that OAM is configured correctly, but the WebGate isn't reporting properly the host header used.
Any ideas? I would very much appreciate any insight or suggestions.
Thanks very muchHi Alex,
Couple of things:
1. Please check if there is any proxy configured in external.domain.com to route requests to internal.domain.com
2. Is Login page residing in same webserver as protected page? If so, it will be different for internal and external domains as it will be seperated by a firewall. I would configure a single authentication scheme without specifying anything in challenge redirect field so that Login page will be thrown from the webserver where it is called for secured page.
3. Please check whether you are able to access login pages of both external and internal domains directly and check for any errors in webserver logs.
Please post the results.
Hope this helps!
-Mahendra -
Selecting a column in a table according to a value
Hi,
I am stuck with a little problem here. I need to fill a column according to a value. I have an xml that will looks like this to make it simple. (Don't worry, I am not managing the status of a stock of Candy ;-))
I have to build in rtf.
<?xml version="1.0" encoding="UTF-8" ?>
- <ROWSET>
- <ROW>
<CANDY>Bubble gum</CANDY>
<SUGAR>SUGARFREE</SUGAR>
</ROW>
- <ROW>
<CANDY>Cinnamon candy</CANDY>
<SUGAR>SUGARFREE</SUGAR>
</ROW>
- <ROW>
<CANDY>Gummy candy</CANDY>
<SUGAR>SUGAR</SUGAR>
</ROW>
</ROWSET>
I have a table with two columns. I need to put on the left column the "SUGARFREE" candy and on the right the "SUGAR" candy.
Is there any condition to make this happen. Or do I have to make two table of one column next to the other and adapt a if condition in the for-each.
best regards,
OlivierHave the same table structure with two columns and have for-each with conditions in each of your columns.
Say in column1: <?for-each:ROW[SUGAR='SUGARFREE']?>text to print <?end for-each?>
column2: <?for-each:ROW[SUGAR='SUGAR']?>text to print <?end for-each?>
Hope this is what you want -
Help in selecting required columns from duplicates records
HI,
I have a table like below
empid,ename,sal,Jdate,Rdate,deptid,designation,Terminated_Emp
1,a,100,15-May-2014,11,SE,NO
1,null,null,15-OCT-14,null,null,YES
I want output like below
1,a,100,15-May-2014,15-OCT-2014,11,SE,YES
Please help me in writing sql query, can we write case condition for this?
NareshHI
And I have to select remaing records from first row only
I mean
empid,ename,sal,Jdate,Rdate,deptid,designation,Terminated_Emp
1,a,100,15-May-2014,null,11,SE,NO
1,null,null,null,15-OCT-14,null,null,YES
2,b,200,12-Jan-2014,null,12,SSE,NO
I want records like
1,a,100,15-May-2014,15-OCT-2014,11,SE,YES
2,b,200,12-Jan-2014,null,12,SSE,NO
Naresh -
Select another column in same table in CF query
Hello..
I'm curious as to the best way to run this query..
When my CF template page loads I would like it to grab a number value in one column and match it up to the table ID in the same table and display the name for that ID.
Do I have to make another table to do this...? QoQ's?
Thanks!Hi Dan..
Sorry I wasnt clearer.. here is a picture.
Thanks for the help! -
Simple Question: JList and JDesktopPane in the same Swing app?
Hi,
I'm really inexperienced with Swing and so have hit what I think is quite a simple problem that I hope someone here can help me with.
I have a class Frame which extends JFrame, I would like to have it contain a JTree running down the left hand side, with the rest of the JFrame taken up by a JDesktopPane. I have sorted out the code for both the JDesktopPane and the JTree independently, and can get them displaying on their own, but how can I display them side by side?
I have a feeling that I have to use some layout manager of some sort and add the JTree and JDesktopPane to it, then add the layout to the JFrame or something but as you can tell I'm a little lost.
I hope that this is a simple problem, it certainly seems quite fundamental and so I hope that someone can help!
Thanks in advance
RichardJFrame by default has a BorderLayout Manager
so to add these two componets for the center one add it as usual, but for the other u have to add it
JFrame.getContentPane().add(instance, BorderLayout.WEST);
or any one of three other values.
hope this is what u ask about -
Select the column details for table in one column as varchar2(32000)
Oracle Version: ORACLE 10G R 2
Problem : Select the column details for some tables and want to store the same in VARCHAR2(32000) separated by ||
Example:
TABLE_NAME COLUMN_NAME DATA_TYPE
EMP EMPNO NUMBER
EMP ENAME VARCHAR2
EMP JOB VARCHAR2
EMP MGR NUMBER
EMP HIREDATE DATE
EMP SAL NUMBER
EMP COMM NUMBER
EMP DEPTNO NUMBER
EMP RN NUMBER
Want to store
COLUMNS (empno||ename||job||mgr||hiredate||sal||comm||deptno||rn);SQL> var cur refcursor
SQL> declare
ctx number;
begin
ctx := dbms_xmlgen.newcontext('select * from emp');
dbms_xmlgen.setNullHandling(ctx, dbms_xmlgen.empty_tag);
open :cur for select * from xmltable('for $i in ROW return string-join($i/*, "||")' passing dbms_xmlgen.getxmltype(ctx).extract('ROWSET/ROW'));
end;
PL/SQL procedure successfully completed.
SQL> print cur
COLUMN_VALUE
7369||SMITH||CLERK||7902||17.12.1980 00:00:00||800||||20
7499||ALLEN||SALESMAN||7698||20.02.1981 00:00:00||1600||300||30
7521||WARD||SALESMAN||7698||22.02.1981 00:00:00||1250||500||30
7566||JONES||MANAGER||7839||02.04.1981 00:00:00||2975||||20
7654||MARTIN||SALESMAN||7698||28.09.1981 00:00:00||1250||1400||30
7698||BLAKE||MANAGER||7839||01.05.1981 00:00:00||2850||||30
7782||CLARK||MANAGER||7839||09.06.1981 00:00:00||2450||||10
7788||SCOTT||ANALYST||7566||19.04.1987 00:00:00||3000||||20
7839||KING||PRESIDENT||||17.11.1981 00:00:00||5000||||10
7844||TURNER||SALESMAN||7698||08.09.1981 00:00:00||1500||0||30
7876||ADAMS||CLERK||7788||23.05.1987 00:00:00||1100||||20
7900||JAMES||CLERK||7698||03.12.1981 00:00:00||950||||30
7902||FORD||ANALYST||7566||03.12.1981 00:00:00||3000||||20
7934||MILLER||CLERK||7782||23.01.1982 00:00:00||1300||||10
14 rows selected. -
Dynamic selection of columns in Portal Report
I have to create a Report, in Oracle Portal, where I select the columns to be displayed according to the value of the language parameter returned by a PL/SQL procedure.
(So, if "English" I display columns A and B, if "French" I display columns A and C, and so on... )
How should I do?
Helps are welcome.
ThanksThe strings replaced by expression <%= v_cell %>
should print the field values contained in col1,col2,col3 columns, but nothing is printed . i think the custom tags (rw...) are not replaced by the jsp expression properly. -
How set disable select matrix column header
How set disable select matrix column header same Inventory-->Pick List Form
Thanks Advance.Hi ,
do u mean Price List Form Header...
If Yes Means Try the Following,
select case pVal.FormType
case "155"
Select Case pVal.Before_Action
case True
select case pval.ItemUid
case "3"
Select Case pVal.EventType
Case SAPbouiCOM.BoEventTypes.et_CLICK
if pval.row = 0 Then BubbleEvent = False : Exit Sub
End Select
End Select
End Select
Regards,
Ganesh k -
Selecting a column base on maximum value
Hi ,
ColumnA ColumnB
A 15
B 45
C 35
D 75
E 55
I need to get Column A based on Max and Min Value of Column B
Here: I need to get the answer as D and A
I could do this using formula or running totals but these only display in either Details, Group Header/Group Footer Sections.
As these values should go between the Text in the report,I need to place these Values in either Report Header/Report Footer.
Thanks,Hi Deep,
If my understanding is correct on your requirement, I have one suggestion.
Can you create sub reports with your working logic and place them in your main report header?
Thanks
Soma -
HOW TO SELECT MIN VALUE UNDER DEFAULT TAG OF SELECT LIST
GREETINGS,
I M USING APEX 4.1 AND CREATED SELECT LIST ON PAGE, I WANT TO SHOW MIN VALUE OF THE SELECT LIST FOR THAT I WROTE IN THAT SELECT LIST PROPERTIEC UNDER DEFAULT TAG MIN; AND CHOOSE PL/SQL EXPRESSION BUT ITS GIVING ERROR "Error computing item default value for page item P1_PRODUCT."
BUT IF I HARCORE THE VALUE CONTANING IN MY DATA LIKE PRODUCT ID = 1, I HARDCODED IN DEFAULT VALUE 1 AND SELECT PL/SQL EXPRESSION IT WORKS.
BUT ITS NOT DONE LIKE THIS I WANT TO SELECT BY DEFAULT MIN VALUE OF THE SELECT LIST, SO THAT THE DATA SHOULD BE DISPLAYED ACCORDING TO THAT.
THE EXACT REQUIREMNT IS TO ENTER THE SELECT LIST DEFULAT VALUE IN SESSION SO THAT DATA IS TO BE DISPLAYEDHi,
you have some options:
1) you can try setting default value of P1_SELECT_PRODUCT item, I was do it
2) or you can try send the value of P1_SELECT_PRODUCT value in URL, like this:
http://apex.oracle.com/pls/apex/f?p=45296:1:0::::P1_SELECT_PRODUCT:4
3) or you can set the session state of P1_SELECT_PRODUCT item on page 101 (login page) by seting this value in Login process on page 101
HELLO kIAS !
SETTING DEAFULT VALUE VALUE OF P1_SELECT_PRODUCT_ITEM IS NOT A SOLUTION ON THIS MATTER, BECASUE P1_SELECT_PRODUCT IS CALLED DYNAMICALY AFTER THE LOGIN DEPEND UPON THE RIGHTS OF THE USER THE SELECT IS POPULATED ID USER IS E.G ABC AND IT DOESBNOT CONTAIN SELECT LIST VALUE 4 THEN IT DISPLAY NOTHING.
AND THIRD POINT MAY BE HELP ME BUT I DONT KNOW HOW TO SET SESION STATE BECASUE WHEN I GO TO LOGIN PAGE AND CREATE SESSION STATE PROCESS FOLLOWING RADIO BUTTOPN APPEARS
Clear Cache For Applications (removes all session state for listed applications)
Clear Cache For Current Application (removes all session state for current application)
Clear Cache For Current Session (removes all state for current session)
Clear Cache for Items (ITEM,ITEM,ITEM)
Clear Cache for all Items on Pages (PageID,PageID,PageID)
Reset Preferences (remove all preferences for current user)
Set Preference to value of Item (PreferenceName:ITEM)
Set Preference to value of Item if item is not null (PreferenceName:ITEM)
WHICH ONE I HAVE TO SELECT ? -
Simple Question: How to search for a date value in SELECT
Probabily a simple question, but in a SELECT statement, how do you do a search for a date value in the WHERE clause?
example:
Select * From Example
Where date = 01/01/2001
I know its not as simple as that, but what change has to occur to make it do what that example implies?
Thanks In Advance.If you want to avoid the conversion part(to_date) you will need to specify the date in the format as ur nls date format.so the same query might not work if you change ur nls date format.
so it is advisable to give it in general format.
ie where date_col=to_date(01-01-2000,'dd-mm-yyyy') -
How do I select a square brush for the brush tool in CS6? Sorry if this is a simple question, but nothing has ever been simple for me in Photoshop.
I don't believe there is a square brush among the sets that ship with Photoshop, but there are plenty to download, and it is super easy to make one.
Just drag with the rectangular Marquee tool, fill with black on a new layer, and go Edit > Define brush preset
Browsing Photoshop Brushes on DeviantArt -
Simple question - How do you make an onchange event occur in a select list
Simple question - How do you make an onchange event occur in a select list to fire a process?
Thanks1) Using ApEx Selec list on Submit Item.
You will create a PL/SQL Process after Submit. -> Conditional Type Request = Expression1. -> Expression1 is the name of your Select List. Process Source - > Procedure you like. For example depending of your select List value you will add rows in different tables.
2) Javascript This example will change a System parameter value when changed
<select id="P3_SUBSYSTEM" onchange="location.href='f?p=101:3:2164422329953284::NO::P3_SUBSYSTEM:'+this.options[selectedIndex].value;" size="1" name="p_t21">
Maybe you are looking for
-
After numerous attempts to install Snow Leopard....
...._(by numerous I mean more than 6 attempts made)_ I have finally thrown in the towel and will be using Leopard (10.5.8)....forever, I suppose. My last attempt(s) (this morning) was to use Pacifist to re-install iCal in Snow Leopard and then using
-
Added a service without permission.
Today I found out my account has been charged for Global data plan ($25/month) from last November. After talking to CS, figured out it was added when they were handling device swapping. I didn't request for it and any text message or email was not se
-
Hello , I have a requirement to display Multiple heading in ALV Grid, I am using the Class 'cl_gui_alv_grid'. please let me know if you have Any suggestions. Ex: | Divison | Sub D:1 Sub D: 2 Sub D: 3 Like
-
Oracle Forms : Master Detail : Cannot query detail block
MY requirement is: when user enters records in master block, the corresponding records should be displayed in the detail block. (Detail block is just for viewing). Master block is a database block based on a custom table. All fields are enetereble in
-
D0025-SE-10911\MSSQLPOSMONITOR\Demo_DW (D0025-SE-10911.TB.NET) The SQL Server 2008 database D0025-SE-10911\MSSQLPOSMONITOR\Demo_DW on D0025-SE-10911.TB.NET is not available. (ID 30164 Details: Internal error code: 0x80990D15) To troubleshoot this iss