Select first rows with rowno
Problem: I search for 20 companies with highest turnover in a table. Its a dynamic SQL (created at runtime), I can not use a hard coded fetch of 20 rows.
(Example is a simple table with companyID, turnover and a key)
I read in documentation, that first rowno is applied, then the order (to be fast and not access the whole big table). Ok.
Oracle goes same way, this is the work around:
SELECT * FROM (SELECT t1.Firmid_i AS t1_Firmid_i, SUM( t1.Amount_dc ) AS t1_Amount_dc FROM DEMO.turnover t1 GROUP BY t1.Firmid_i, t1.Productid_i ORDER BY 2 desc ) WHERE rownum <= 20
I try this on a MaxDb :
SELECT * FROM (SELECT t1.Firmid_i, MAX( t1.Amount_dc ) FROM DEMO.turnover t1 GROUP BY t1.Firmid_i ORDER BY 2 asc) WHERE rowno <= 20
-> an error occur (General error;-5016 POS(103) Missing delimiter: ), the order in the inner sql is not allowed
I can change the statement:
SELECT * FROM (SELECT t1.Firmid_i, MAX( t1.Amount_dc ) FROM DEMO.turnover t1 GROUP BY t1.Firmid_i) WHERE rowno <= 20 ORDER BY 2 asc
Now I got 20 row (20 rows sorted), but not the results I need (sort is used to late).
Does anyone knows a workaroud?
TIA
Christian
Hello Christian,
Unfortunately, MaxDB does not support the ORDER BY/GROUP BY condition in sub-selects to achieve such a result set limitation, nor does it support a kind of LIMIT statement
as MS-SQL does.
Anyway, to give the correct results, the query will anyway
create the complete result set, to apply the correct sorting (as the rows can only be sorted when for all rows the values are known).
There is unfortunately no way to formulate such a query
in a single SQL statement, and so you can only
fetch as much rows you need, and discard the rest,
which you said is not possible for you.
Sorry
Alexander Schröder
Similar Messages
-
Af:inputListOfValues popup : selecting first row
Hi,
Is there a way to select first row inside lov popup, the by default behaviour is it selects the rowHeader rather than row itself.
When the lov popup is opened , there is no focus on table resides in the popup
- to focus on table, user has to press down arrow key - which will just focus on rowHeader and not the actual row itself
- to focus row for currently selected rowHeader user has to press right arrow key which will then select the table row itself
its cumbersome everytime when you open lov and do these extra steps to just to select a value from lov
any ideas?
Thanks,
Devso, why it supports keyboard navigation at all? either support full features or nothing. the fact that user can use up/down arrow keys which selects rowHeader of every row , rather than actual row
regarding "Search and Select : " it could be anything it has nothing to do with row selection,
Thanks, -
Hi.i want to select only rows with no child rows
Hi.i want to select only rows with no child rows in hierarchical queries.
http://www.rampant-books.com/10g_80.htm
bye
TPD -
How to select first row of each group in a group by statement
Table
ProdCode PackType BatchCode ExpDate
BURSLO 1 BS20GO-2001 01/12/2004
BURSLO 1 BS20GO-2011 01/01/2007
BURSLO 2 BS20GO-2027 01/02/2003
BURSLO 3 BS20GO-2060 01/02/2004
BURSOI 9 BU10F12 01/02/2006
BURSOI 9 BU10GO-1301 01/05/2005
BURSOI 11 BU10GO-131 01/06/2008
BURSOI 2 BU10GO-1311 01/06/2007
BURSOI 13 BU10GO-1328 01/07/2006
Output
ProdCode PackType BatchCode ExpDate
BURSLO 1 BS20GO-2011 01/01/2007
BURSLO 2 BS20GO-2027 01/02/2003
BURSLO 3 BS20GO-2060 01/02/2004
BURSOI 9 BU10F12 01/02/2006
BURSOI 11 BU10GO-131 01/06/2008
BURSOI 2 BU10GO-1311 01/06/2007
BURSOI 13 BU10GO-1328 01/07/2006
i need first row after group by ProdCode, PackType and decreading order of ExpDate
Please Help me.
Thanks.
Try the below:
;With cte
as
(Select *,Row_Number()Over(partition by Prodcode,Packtype Order by expdate desc) Rn From Tablename)
Select * From cte where rn=1 -
Hi,
I have a page with two tables - Master-Detail. Upon first load of the page, I would like the first row in the master table got selected automatically, and so the detail table is displayed with the corresponding data for the master. I have implemented similar page before, and the first row always got selected automatically. But not sure why, for this page, none of the rows in the table got selected upon first load of the page. I have to manually highlight a row in the master table, then the detail table will display the corresponding data.
Any ideas?
Thanks.
-MinaYes, I did set the partial trigger. That's why when manually select the row on the master table, the detail table get refreshed. The problem is the first time entering the page, and not row get selected automatically in the master table. Here is the code snipplet of the detail table:
<af:table value="#{bindings.ItasLookupCodesVO1.collectionModel}"
var="row" rows="#{bindings.ItasLookupCodesVO1.rangeSize}"
emptyText="#{bindings.ItasLookupCodesVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.ItasLookupCodesVO1.rangeSize}"
rowBandingInterval="0"
filterModel="#{bindings.ItasLookupCodesVO1Query.queryDescriptor}"
queryListener="#{bindings.ItasLookupCodesVO1Query.processQuery}"
filterVisible="true" varStatus="vs"
selectedRowKeys="#{bindings.ItasLookupCodesVO1.collectionModel.selectedRow}"
selectionListener="#{bindings.ItasLookupCodesVO1.collectionModel.makeCurrent}"
rowSelection="single" id="t2" partialTriggers=":::pc1:t1"
editingMode="clickToEdit" summary="Lookup Codes">
The table is a child of a panelCollection.
Any more ideas?
Thanks.
-Mina -
Selecting the rows with the max rank
Using Siebel CRM and tested conditions in Answers - It was observed that one email ID is linked to multiple customers. For an email campaign we need to select only one customer per email basically had to remove all the duplicate email addresses from the list as customer IDs are anyways unique.
Tried using the RANK function - RANK(customer ID by Email) = 1 it gave me unique email addresses and customer IDs but the problem is that the RANK 1 is given to the latest customer added (customer IDs are numeric)
I need a solution to select all the rows with the max rank / all the customers that were added first for all the emailsDon't know what you want to achieve but here is way to do this:
SQL> select * from test;
NO
1
2
3
4
5
SQL> select * from test union all select * from test;
NO
1
2
3
4
5
1
2
3
4
5
10 rows selected.
Daljit Singh -
Alv colour row select first row
Hi. I hava an alv with colour in some rows. When i want to select another row distint the first, it always goes to de first row and it doesn't allow me select other row.
how can i solve this to select for example the third row.
thanks.Hi,
Are you programatically setting the selection of the ALV row anywhere in your program? This might happen if you set the lead selection of the node in the WDDOMODIFYVIEW method of your view. Can you please check that ? Also you can try changing the selection mode of your ALV:
lo_config_model_value = lo_interfacecontroller->get_model( ).
lo_config_model_value->IF_SALV_WD_TABLE_SETTINGS~SET_SELECTION_MODE(CL_WD_TABLE=>E_SELECTION_MODE-AUTO).
Best Rgds,
Viqar. -
First Row with $s n below w/o $s
For a hierarchy is it poss to show the amounts with $ sign in the first row & without the $ signs below ??
Something like say for a country Hierarchy :
<b>-Month--
Year to date</b>
2007|2006|INC ( Diff ) |%________________2007|2006|INC ( Diff ) |%
USA Amount----$50,000|$40,000_|$10,000______|25(10/40)_________$1000|$800|$200____|25
TexasAmount----50,00|40,00_|10,00______|25(10/40)_________1000|800|200____|25
How do I accomplish or any workaround to get close by..
I have tried scaling factor but that is showing a seperate grey column with dollar signs....
I found a close workaround to suppress all $ amounts :
I had to create 4 new Formulaes with the Nodim Function & make the other 4 as formula NODIMS and Hide the 4 Selectoins .
Ex : NODIM ( SELECTION1 )
_____Selectoin1 - Hidden.
However this is not I wanted
<b>Is there any other efficient way to get $ signs in first row only suppressing the signs in all below rows ?</b>
Message was edited by:
Jr RobertoHi Roberto,
Try to include the $ sign in the Header.(i.e. in Structure Selections)
Your header should look like
2007|2006|Diff|
$ $ $
Then use the NODIM Function to suppress the $ sign in below row results.
Cheers
Praveen -
How to select first row of JTable by default
Hi,
I have a JTable with 5 rows.
When the software starts, none of the rows are selected.
I wish to keep the first row selected by default.
How do I do it?
I couldnt find any method like setSelectedRow() !!!
Does anyone have a sample code plz?
Thanks.
Anujcouldnt find any method like
setSelectedRow()You need to use getSelectionModel() first.
Another way is to use:
table.changeSelection(0, 0, false, false); -
Af:tableselectmany always selects first row and ONLY first row
My table in jsp:
<af:table value="#{bindings.AluNoExpeAluM1.collectionModel}" var="row"
rows="#{bindings.AluNoExpeAluM1.rangeSize}"
first="#{bindings.AluNoExpeAluM1.rangeStart}"
emptyText="#{bindings.AluNoExpeAluM1.viewable ? \'No rows yet.\' : \'Access Denied.\'}"
binding="#{cient20uSeleccionAluBean.tablaMultiple}">
<af:column sortProperty="Vnumdocu" sortable="false"
headerText="#{bindings.AluNoExpeAluM1.labels.Vnumdocu}">
<af:outputText value="#{row.Vnumdocu}"/>
</af:column>
<af:column sortProperty="Vapeynombre" sortable="false"
headerText="#{bindings.AluNoExpeAluM1.labels.Vapeynombre}">
<af:outputText value="#{row.Vapeynombre}"/>
</af:column>
<f:facet name="selection">
<af:tableSelectMany text="Select items and ..." autoSubmit="true">
<af:commandButton text="commandButton 1"
action="#{cient20uSeleccionAluBean.elegirAlumnoAction}"
partialSubmit="true" immediate="true"/>
</af:tableSelectMany>
</f:facet>
</af:table>
Table don't have SelectionListener and SelectionState, but the method only select the first row from iterator.
This method "elegirAlumnoAction":
public String elegirAlumnoAction() {
Iterator itRs = this.getTablaMultiple().getSelectionState().getKeySet().iterator();
while(itRs.hasNext()){
Key k = (Key) itRs.next();
System.out.println(k.toString());
Row r = IteratorUtil.obtenerIteradorPorDefecto(this.ITERADOR_RESULTADO).getRow(k);
System.out.println(r.getAttribute("Vnumdocu"));
IteratorUtil.obtenerIteradorPorDefecto(this.ITERADOR_RESULTADO).setCurrentRow(r);
return null;
Message was edited by:
jortri
Message was edited by:
jortriMaybe the following can help you:
http://andrejusb.blogspot.com/2007_02_01_archive.html
http://andrejusb-samples.blogspot.com/2007/02/jdevadf-sample-multi-selection-feature.html -
How do I select the row with the most recent date/time?
We have a medication report that needs the last administration time displayed. Can anyone help with a selection formula that chooses the max date?
The easiest thing to do is sort by the date (descending), and show the first record, suppressing all others until the next medication, patient, or whatever your grouping is. This is done with a global variable: Set it to FALSE at the beginning of the group(s), suppress the detail line based on the value of the variable, and then set it to TRUE (which can also be done in the Suppress Format formula).
HTH,
Carl -
Select thousand rows with dbadapter
hi guys,
anyone have tried to select thousand of rows data from database using soa db adapter ?
everytime i tried to select more than 5000 rows, then it will turn into error.
i'm using jdev 11.1.1.7 soa 11.1.1.7
error code from console
[code]
<Jan 7, 2014 5:46:52 PM ICT> <Error> <EJB> <BEA-010026> <Exception occurred during commit of transaction Name=[EJB com.collaxa.cube.engine.ejb.impl.bpel.BPELDeliveryBean.handleInvoke(com.collaxa.cube.engine.dispatch.message.invoke.InvokeInstanceMessage)],Xid=BEA1-1E4FA285A12B8F14E263(57883289),Status=Rolled back. [Reason=weblogic.transaction.internal.TimedOutException: Transaction has timed out when making request to XAResource 'jdbc/apps_bpm_domain'.],numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds since begin=307,seconds left=54,XAServerResourceInfo[SOADataSource_bpm_domain]=(ServerResourceInfo[SOADataSource_bpm_domain]=(state=rolledback,assigned=soa_server1),xar=SOADataSource,re-Registered = false),XAServerResourceInfo[jdbc/smhr_bpm_domain]=(ServerResourceInfo[jdbc/smhr_bpm_domain]=(state=rolledback,assigned=soa_server1),xar=jdbc/smhr,re-Registered = false),XAServerResourceInfo[jdbc/apps_bpm_domain]=(ServerResourceInfo[jdbc/apps_bpm_domain]=(state=rolledback,assigned=soa_server1)
,xar=jdbc/apps,re-Registered = false),SCInfo[bpm_domain+soa_server1]=(state=rolledback),properties=({weblogic.transaction.name=[EJB com.collaxa.cube.engine.ejb.impl.bpel.BPELDeliveryBean.handleInvoke(com.collaxa.cube.engine.dispatch.message.invoke.InvokeInstanceMessage)]}),local properties=({weblogic.jdbc.jta.SOADataSource=[ No XAConnection is attached to this TxInfo ], weblogic.jdbc.jta.jdbc/apps=[ No XAConnection is attached to this TxInfo ], weblogic.jdbc.jta.jdbc/smhr=[ No XAConnection is attached to this TxInfo ]}),OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=(CoordinatorURL=soa_server1+10.206.131.27:8001+bpm_domain+t3+, XAResources={SOADataSource_bpm_domain, eis/Apps/Apps, eis/tibjms/Queue, eis/activemq/Queue, WLStore_bpm_domain__WLS_soa_server1, EDNDataSource_bpm_domain, WLStore_bpm_domain_SOAJMSFileStore, WLStore_bpm_domain_UMSJMSFileStore_auto_2, eis/webspheremq/Queue, eis/AQ/aqSample, eis/fioranomq/Topic, eis/aqjms/Queue, eis/sunmq/Queue, eis/pramati/Queue, j
dbc/hr_bpm_domain, eis/tibjms/Topic, eis/tibjmsDirect/Queue, eis/jbossmq/Queue, WSATGatewayRM_soa_server1_bpm_domain, eis/wls/Queue, eis/tibjmsDirect/Topic, WLStore_bpm_domain_AGJMSFileStore, WLStore_bpm_domain_BPMJMSFileStore, eis/wls/Topic, WLStore_bpm_domain_PS6SOAJMSFileStore, eis/aqjms/Topic, jdbc/smhr_bpm_domain, jdbc/apps_bpm_domain},NonXAResources={})],CoordinatorURL=soa_server1+10.206.131.27:8001+bpm_domain+t3+): weblogic.transaction.RollbackException: Transaction has timed out when making request to XAResource 'jdbc/apps_bpm_domain'.
[/code]
pls throw some light.
thanksby default the value of the timeout is zero (0). it has no timeout for my understanding.
now i'm trying to find workaround.
i'll create 2 soa composite. 1 for get 500rows of data every time invoked. and 1 to loop to call the 1st composite.
this one work but have a intermittent error.
1st issue is i have to allocate a lot of connection pool to handle lots of db connection based on the db row data.
2nd issue i can't trace the xml in SOA EM composite request.
is the only way is to let the copy data from 1 database to another database handled by the DB ? cannot utilize the soa ? -
Select first row from every set
id num dtl sdate udate
4 4JQ010907 MO601159736142323333 09-NOV-03
4 4JQ010907 MO601159736142323333 09-NOV-03 08-DEC-03
4 4JQ010907 MO601159736142323333 09-NOV-03 08-NOV-04
4 4JQ010907 MO601159736142323333 09-NOV-03 09-DEC-03
4 4JQ014529 W436-5902-285308-17-00 30-JAN-04
4 4JQ014529 W436-5902-285308-17-00 30-JAN-04 02-FEB-04
4 4JQ014529 W436-5902-285308-17-00 30-JAN-04 08-NOV-04
For each record having the same num, i want only one record picked, and that one should not have udate blank.
How can I do this using ROWNUM?...but there is a pitfall when the columns in selection list are not the same to
columns in order by. Here unique can't help (while row_number() will
also return one row (another question is it wnat you need or not):
Compare:
SQL> select ename, deptno,sal from emp_1 order by 2,1;
ENAME DEPTNO SAL
CLARK 10 1225
CLARK 10 2450
KING 10 2500
KING 10 5000
MILLER 10 650
MILLER 10 1300
ADAMS 20 550
ADAMS 20 1100
FORD 20 1500
FORD 20 3000
JONES 20 1487,5
JONES 20 2975
SCOTT 20 1500
SCOTT 20 3000
SMITH 20 500
SMITH 20 1000
ALLEN 30 900
ALLEN 30 1800
BLAKE 30 1425
BLAKE 30 2850
JAMES 30 560
JAMES 30 1120
MARTIN 30 625
MARTIN 30 1250
TURNER 30 750
TURNER 30 1500
WARD 30 725
WARD 30 1450
28 rows selected.
SQL> select ename, deptno, sal from
2 (select ename, deptno, sal,
3 dense_rank() over(partition by deptno order by ename) rn
4 from emp_1) where rn = 1
5 /
ENAME DEPTNO SAL
CLARK 10 1225
CLARK 10 2450
ADAMS 20 550
ADAMS 20 1100
ALLEN 30 900
ALLEN 30 1800
6 rows selected.
SQL> select unique ename, deptno, sal from
2 (select ename, deptno, sal,
3 dense_rank() over(partition by deptno order by ename) rn
4 from emp_1) where rn = 1
5 /
ENAME DEPTNO SAL
CLARK 10 1225
CLARK 10 2450
ADAMS 20 550
ADAMS 20 1100
ALLEN 30 900
ALLEN 30 1800
6 rows selected.
SQL> select ename, deptno, sal from
2 (select ename, deptno, sal,
3 row_number() over(partition by deptno order by ename) rn
4 from emp_1) where rn = 1
5 /
ENAME DEPTNO SAL
CLARK 10 1225
ADAMS 20 550
ALLEN 30 900Rgds. -
How to select one row with such sql
hi , everyone
I got a headache about this sql:
select * from E_VPN_pbxlink where ((SPILOTNUM ='1234' ) or (SPILOTNUM ='123')) order by SPILOTNUM desc ;
it retruns 2 records.
I need to get the record with SPILOTNUM ='1234' , how can I reform this sql
tksHi,
I think I see:
You want the longest spilotnum that starts with the same charachters as the parameter.
You can do a Top-N Query like this:
WITH got_rnum AS
select e.*
, RANK () OVER (ORDER BY LENGTH (spilotnum DESC) AS rnum
from E_VPN_pbxlink
where '123456' LIKE SPILOTNUM || '%'
SELECT * -- or list all columns except rnum
FROM got_rnum
WHERE rnum = 1
;There is a slightly simplerr way, using the ROWNUM pseudo-column, but its only slightly easier, and it won't help if, say, you want to pass two or more targets such as '123456' in the same query. -
Selecting multiple rows using column header with checkbox in it.
Dear All.,
I am trying to select multiple rows with checkbox in column header but it doesnot works...
Following is my codel
<af:table value="#{bindings.xx.collectionModel}"
var="row"
rows="#{bindings.xx.rangeSize}"
emptyText="#{bindings.xx.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.xx.rangeSize}"
rowBandingInterval="1"
filterModel="#{bindings.xx.queryDescriptor}"
queryListener="#{bindings.xx.processQuery}"
varStatus="vs" partialTriggers="sbcSelectAll sbcChkFlag"
selectedRowKeys="#{bindings.xx.collectionModel.selectedRow}"
selectionListener="#{bindings.xx.collectionModel.makeCurrent}"
rowSelection="none" id="tCdMast" width="400"
columnStretching="column:c4" inlineStyle="height:200px;">
<af:column sortProperty="ChkFlag" filterable="true"
sortable="true"
headerText="#{bindings.xx.hints.ChkFlag.label}"
id="c2" width="55"
inlineStyle="#{row.ChkFlag ? 'background-color:#9CACC9;' : ''}">
<af:selectBooleanCheckbox simple="true" value="#{row.ChkFlag}"
selected="#{row.ChkFlag}" id="sbcChkFlag"
autoSubmit="true" immediate="true"/>
<f:facet name="header">
<af:selectBooleanCheckbox simple="true"
autoSubmit="true"
valueChangeListener="#{xxBean.onTableChkAllCheckChanged}"
id="sbcSelectAll"/>
</f:facet>
</af:column>
</af:table>
Managed Bean
public void onTableChkAllCheckChanged(ValueChangeEvent valueChangeEvent) {
Boolean newValue =
Boolean.valueOf(u.nvlString(valueChangeEvent.getNewValue(),
"false"));
Boolean oldValue =
Boolean.valueOf(u.nvlString(valueChangeEvent.getOldValue(),
"false"));
if (newValue.equals(oldValue))
return;
int rowIndex=0;
ViewObject vo = u.findIterator("xxIterator").getViewObject();
vo.reset();
while(vo.hasNext()){
Row row;
if(rowIndex==0)
row=vo.first();
else
row=vo.next();
row.setAttribute("ChkFlag", newValue.booleanValue());
rowIndex=1;
u.addPartialTargets(tableDocuments);
}Please help!!.
Thanks & Regards,
Santosh.
jdeve 11.1.1.4.0Can you check this sample in the blog post?
http://sameh-nassar.blogspot.com/2009/12/use-checkbox-for-selecting-multiple.html
Thanks,
Navaneeth
Maybe you are looking for
-
Hi Friends, How to get item text in output (Smartform), which is maintained at Sales order Item Level - Text Tab aginast a line item. Pls reply me the table name and fielnd name. Text is maintianed almost 20 words (100 Char) Srikky.
-
I purchased my Acrobat 9 pro as a digital download. It just recently stopped working and I don't know how to repair it. I need it up and running ASAP!!! Please help!
-
So, How can I move my newly transformed docx into Word so I can edit it???
-
A couple of functions don't work anymore (ical, qucik time), things I actually use quite frequently. I am not satisfied at all with Lion and would wish to cancel my purchase. Apple is trying its best to hide any potential contacts, so does anyone hav
-
How can I reduce a 5MB photo to 4.5MB without cropping?
For a photo contest I can't submit photos over 5MB, yet the 3 photos I have in the JPEG format in iPhoto to submit are 5.1MB to 8MB in size. Cropping is not an option. Any ideas??? Thanx