How to fetch a row with maximum rownum
In my sql query, how can i fetch the row with max row count? the query has around 10 columns.
Thank You
KK
Hi,
It's not very clear what you want.
It sounds like you want a Top=-N Query , perhaps like this:
WITH got_row_cnt AS
SELECT job
, COUNT (*) AS row_cnt
-- , ... -- other columns
, RANK () OVER (ORDER BY COUNT (*) DESC) AS rnk
FROM scott.emp
GROUP BY job
SELECT * -- or list all columns except rnk
FROM got_row_cnt
WHERE rnk = 1
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
Similar Messages
-
How to fetch indivdual rows from a dynamic query.
Hi,
I wish to fetch the individual rows returned from a dynamic query.
if my dynamic query is:
dyn_stmt := select col1, col2, col3
from tab1;
The query returns multiple rows.
Then how to fetch individual rows of this query ?
Please explain.declare
cur_test sys_refcursor;
c1 varchar2(30);
c2 number;
c3 date;
begin
dyn_stmt := select col1, col2, col3 from tab1;
OPEN cur_test FOR dyn_stmt;
LOOP
FETCH cur_test INTO c1, c2, c3;
IF cur_test%NOTFOUND THEN
EXIT;
END IF;
-- Process this row
END LOOP;
CLOSE cur_test;
END; -
How to fetch service order with partucular system status and user status
Hello All,
How to fetch service orders with specific system status and user status.
thanksI want tables or views from where I can fetch service orders. I have to design ALV report based on this.
I want to fetch released service orders with status INIT and RENT.
Here, SYSTEM Status = Released and
USER Status = INIT
RENT
So is there any function module available for the same..... -
How to fetch n rows at a time?
I know that I can use the rownum function to return n rows at a time, but the rownum function will be applied after all rows are returned by the query, which is bad for performance since my table has lot of rows. What I need is really to fetch n rows at a time from the DB.
RegardsI am not sure what you mean by "the rownum function will be applied after all rows are returned by the query", but that appears to be an incorrect statement. If you have a ROWNUM limit in a query, Oracle knows that it only has to fetch the first M rows.
If you are looking for an ability to page through query results, there is an AskTom thread on pagination in SQL.
This would only be appropriate, though, if you expect that users will only ever want the first few pages of results (i.e. users of Google aren't going to look through every page of results for generic search terms, they are going to look at page 1, maybe page 2 and page 3, and then stop). If the application is going to process all the rows that the query returns, you'd need some other construct and we would need some additional requirements. Your client application can probably fetch N rows at a time. If the client is PL/SQL, a BULK COLLECT with a LIMIT clause may also be appropriate.
Justin -
How to populate table rows with selected listbox items?
Hello,
I am trying to populate a table with selected listbox items. Each item should be a new row in the table. The picture below is the listbox and table I am using. I need to get the selected name to populate the Attendee column of the table when the user clicks the Add button. How do you do this with mutltiple attendees selected?
Thank you,
AngieSo you're considering the fact the if the user clicks the button twice, the name will appear twice and you don't want this, right?
Then you must check if any value is the same than the one you are about to add in the row..
for (var i = 0 ; i < ListBox1.length; i++){
if (ListBox1.getItemState(i) == true){
for (var x = 0 ; x < Table1._Row1.count; x++){
var boNewAttendee = true;
var strAttendee = Table1.resolveNode("Row1[" + x.toString() + "]").txtAttendee;
var newAttendee = ListBox1.getDisplayItem(i);
if (strAttendee.rawValue == newAttendee){
boNewAttendee = false;
break;
if (boNewAttendee){
txtAttendee.rawValue = ListBox1.getDisplayItem(i); -
How to get internal table with maximum value of a field in other internal
Let say I have an table itab consisting of:
itab-matnr = marm-matnr.
itab-umren = marm-umren.
itab-ean11 = marm-ean11.
there are many "ean11" for one "matnr"
How could I create itab2 with only "biggest" "ean11". could you give me examlpleHi,
data: mat_no type MATNR.
Loop at ITAB1.
IF mat_no = itab1-matnr.
here check the ean11 with previos ean11(Store it like matnr), and move the biggest one andf modify that row or move that in ITAB2 with a Modify statment, so that there will no second row with same material No
ENDIF.
MAT_NO = ITAB1-Matnr (Moving Itab1 material no to a Local field)
ENDLOOP.
Endloop. -
How to maintain dynamic rows with data when click on Previous button?
Hi,
I have 1 aspx page and divided into 3 pages using panels.Each panel has "Next" and Previous buttons
I have created and deleted dynamic table rows when click on Add button using javascript. whenever i click on Next button it will navigate to same page of next panel.
when i click on previous button then it goes to previous panel but whatever i have added dynamic table rows in 1st panel that got removed.
Can u please help me for how to maintain state of dynamic table rows with entered data when click on Previous button?
How to get dynamic table rows with entered data in previous panel when click on Previous button?
Please find the below javascript code:
function insertRow() {
if (index >= 2) {
document.getElementById('deleteRow').style.display = "inline";
else { document.getElementById('DeleteRow').style.display = "none"; }
var table = document.getElementById("myTable");
var row = table.insertRow(table.rows.length);
cell1 = row.insertCell(0);
t1 = document.createElement("select");
t1.options[t1.options.length] = new Option('--Select--', '0');
t1.id = "ddlYear" + index;
cell1.appendChild(t1);
for (var i = 1975; i <= 2015; i++) {
opt = document.createElement("option");
opt.value = i;
opt.text = i;
t1.add(opt);
t1.style.width = "155px";
var cell2 = row.insertCell(1);
t2 = document.createElement("Select");
t2.options[t2.options.length]=new Option('--Select--','0');
t2.options[t2.options.length]=new Option('State Board','1');
t2.options[t2.options.length]=new Option('CBSE','2');
t2.options[t2.options.length]=new Option('ICSE','3');
t2.options[t2.options.length] = new Option('Others', '4');
t2.style.width = "155px";
t2.id = "ddlCourse" + index;
cell2.appendChild(t2);
var cell3 = row.insertCell(2);
t3 = document.createElement("input");
t3.id = "txtCity" + index;
cell3.appendChild(t3);
var cell4 = row.insertCell(3);
t4 = document.createElement("input");
t4.id = "txtInstitute" + index;
cell4.appendChild(t4);
var cell5 = row.insertCell(4);
t5 = document.createElement("Select");
t5.options[t5.options.length] = new Option('--Select--', '0');
t5.options[t5.options.length] = new Option('English', '1');
t5.options[t5.options.length] = new Option('Hindi', '2');
t5.options[t5.options.length] = new Option('Telugu', '3');
t5.options[t5.options.length] = new Option('Others', '4');
t5.style.width = "155px";
t5.id = "ddlMedium" + index;
cell5.appendChild(t5);
var cell6 = row.insertCell(5);
t6 = document.createElement("input");
t6.id = "txtSpecialization" + index;
cell6.appendChild(t6);
var cell7 = row.insertCell(6);
t7 = document.createElement("input");
t7.id = "txtFnl" + index;
cell7.appendChild(t7);
index++;
function DeleteRow(index) {
var table = document.getElementById("myTable");
table.deleteRow(index);
// if (index = 2) { alert("There is no rows added.Please add the new row"); }
Design:
<tr style="font-size: 12pt" id="trSecond" runat="server">
<td colspan="3">
<table id="myTable" width="100%" border="0">
</table>
<tr>
<td colspan="3" align="right">
<input type="button" title="Add" value="Add" onclick="insertRow();" />
<input type="button" id="deleteRow" title="Delete" value="Delete Row" onclick="DeleteRow(this);" style="display:none" />
</td>
</tr>
Thank you.Put the button click into an action listener and build the new frame there. The code I have below isn't exactly what you're doing (it's amazingly oversimplified), but it's probably similar enough to get your wheels turning in the right direction.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class sample
public static void main(String[] args)
JFrame frame = new JFrame("Sample");
frame.setSize(400,400);
Container content = frame.getContentPane();
content.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField text = new JTextField(10);
content.add(text);
JButton button = new JButton("Send");
content.add(button);
frame.setVisible(true);
button.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
JFrame myframe = new JFrame("Results");
myframe.setSize(200,200);
Container mycontent = myframe.getContentPane();
mycontent.setLayout(new FlowLayout());
String mytext = text.getText();
JLabel label = new JLabel();
label.setText(String.valueOf(mytext));
mycontent.add(label);
myframe.setVisible(true);
} -
SQL batch doesn't work; How to fetch related objects with fetch group?
I have two questions:
1. SQL Batch doesn't seem to work. I have tested some batch object creation
with BatchLimit set to -1, 0, 1, 25, 100. They all have similar
performance.
kodo.jdbc.DBDictionary: BatchLimit=25
2. How to use custom fetch group to fetch related objects? The example of
custom fetch group only show how to fetch different attributes in different
groups. I have a test cases where I would like to pre-fetch related objects
to save round trip.
Enviroments:
* Kodo 3.1.0 RC1
* Oracle 9i release 1
Thanks for any help!
Qingshan Luo
Senior Software Engineer
Open Harbor
1123 Industrial Road
San Carlos, CA 94070
Phone: 650-413-4251
Fax: 650-413-4298try poracle 10g driver. At least they fixed terrible CLOB bug may be batch
to. BTW 9.2.x has problem with batching with deferred constraints so be
careful
"Greg Campbell" <[email protected]> wrote in message
news:c3dmnu$rmj$[email protected]..
>
"Qingshan Luo" <[email protected]> wrote in message
news:c3dg7q$mdl$[email protected]..
Hi,
I have two technical questions with Kodo.
1. SQL Batch doesn't seem to work. I have tried batch size of -1, 0, 1,25.
But the performance from batch creating objects is not affected by batch
size.
kodo.jdbc.DBDictionary: BatchLimit=25You may be running into a bug in the Oracle 9.2 driver. That driverdoesn't
reliably give update counts when using batching and prepared statement
caching. By default, Kodo will turn off batching. You can manuallyenable
batching by setting the BatchLimit on your DBDictionary, as you've done.If
you do this, though, you may want to turn off prepared statement cachingby
setting MaxCachedStatements to 0 (see
http://www.solarmetric.com/Software/Documentation/3.1.0RC1/docs/ref_guide_dbsetup.html#ref_guide_dbsetup_builtin).
>
2. How to use custom fetch groups to eagerly fetch related persistable
objects? Example only showed attributes, not relationships.You can find information on setting up eager fetching of relations at
http://www.solarmetric.com/Software/Documentation/3.0.3/docs/ref_guide_
perfpack_eager.html
Basically, you'll need to add the relations to your fetch group, and
set the eager fetching mode.
Enviroment:
* Kodo 3.1.0 RC1
* Oracle 9i release 1.
Qingshan Luo
Senior Software Engineer
Open Harbor
1123 Industrial Road
San Carlos, CA 94070
Phone: 650-413-4251
Fax: 650-413-4298 -
How to fetch all fields with RFC_READ_TABLE ?
I can use RFC_READ_TABLE to fetch specified fields with the TABLE parameter "FIELDS". If I want to fetch all fields of the table, I must specified each field name. However, I can not use "*" in FIELDS, and I can not left the table empty (Error will be generated). Is there other method to fetch all fields ?
language: VB.NET
tblT = New TAB512Table
tblTField = New RFC_DB_FLDTable
tblTOption = New RFC_DB_OPTTable
Dim stuTFieldRow As New RFC_DB_FLD
Dim stuTOptionRow As New RFC_DB_OPT
Sapproxy.Rfc_Read_Table("", "", strTN, 0, 0, tblT, tblTField, tblTOption)Hi:
Do like this
CALL FUNCTION 'RFC_READ_TABLE'
EXPORTING
query_table = Table
delimiter = ''
no_data = ''
rowskips = 0
rowcount = 0
TABLES
options = i_options
fields = i_fields
data = t_data.
Regards
Shashi -
How to join each row with other in the same table without repeating, please help
Hi,
I have a table say Adjustment having following data
Emp_Id
Adjustment_id
Date
1000101
1000300
2014-02-12 00:00:00.000
1000101
1000301
2014-02-12 00:00:00.000
1000101
1000302
2014-02-12 00:00:00.000
1000101
1000303
2014-02-12 00:00:00.000
1000102
1000302
2014-02-12 00:00:00.000
1000102
1000303
2014-02-12 00:00:00.000
1000102
1000304
2014-02-12 00:00:00.000
And I want following records:
Emp_Id
Adjustment_id Adjustment_id1
Date
1000101
1000300 1000301
2014-02-12 00:00:00.000
1000101
1000300 1000302
2014-02-12 00:00:00.000
1000101
1000300
1000303
2014-02-12 00:00:00.000
1000101
1000301 1000302
2014-02-12 00:00:00.000
1000101
1000301 1000303
2014-02-12 00:00:00.000
1000101
1000302 1000303
2014-02-12 00:00:00.000
1000102
1000302 1000303
2014-02-12 00:00:00.000
1000102
1000302 1000304
2014-02-12 00:00:00.000
1000102
1000303
1000304
2014-02-12 00:00:00.000Hi Uri,
I am using SQL Server 2008, and I am trying join each adjustment_id with all other adjustment_id having same Date and Emp_id.
so for following table records:
Emp_Id
Adjustment_id
Date
1000102
1000302
2014-02-12 00:00:00
1000102
1000303
2014-02-12 00:00:00
1000102
1000304
2014-02-12 00:00:00
Output should be:
Emp_Id
Adjustment_id Adjustment_id
Date
1000102
1000302 1000303
2014-02-12 00:00:00 (first row with 2nd)
1000102
1000302 1000304
2014-02-12 00:00:00 (first row with 3rd)
1000102
1000303 1000304
2014-02-12 00:00:00 (2nd row with 3rd) -
How to fetch count along with other details
I am trying to write a simple Select query that will return a list of
Employee Names from EMPLOYEE_TABLE,and in the second colum a count of the
number of entries for each employee in EMPLOYEE_ATTENDANCE table.
Can anybody suggest how I could do this?
For Example :
I have two tables EMPLOYEE_TABLE and EMPLOYEE_ATTENDENCE .
EMPLOYEE_TABLE:
emp_number emp_name
1 A
2 B
3 C
4 D
EMPLOYEE_ATTENDENCE :
emp_number emp_time
1 8.00
1 8.00
1 8.00
4 8.00
4 9.00
4
4
4
3
3
3
2
Now ,my requirement is I want to fetch the list of employees with emp_name and the number of days
the employee has come(i.e number of entries in the EMPLOYEE_ATTENDENCE table ).
Some like :
A 3
B 1
C 3
D 5Just you have to join them and group it.
SQL> with emp
2 as
3 (
4 select 1 no, 'A' name from dual
5 union all
6 select 2, 'B' from dual
7 union all
8 select 3, 'C' from dual
9 union all
10 select 4, 'D' from dual
11 ),
12 emp_att
13 as
14 (
15 select 1 no, 8.00 tm from dual
16 union all
17 select 1, 8.00 from dual
18 union all
19 select 1, 8.00 from dual
20 union all
21 select 4, 8.00 from dual
22 union all
23 select 4, 9.00 from dual
24 union all
25 select 4, 0 from dual
26 union all
27 select 4, 0 from dual
28 union all
29 select 4, 0 from dual
30 union all
31 select 3, 0 from dual
32 union all
33 select 3, 0 from dual
34 union all
35 select 3, 0 from dual
36 union all
37 select 2, 0 from dual
38 )
39 select name,count(name)
40 from emp e, emp_att a
41 where e.no = a.no
42 group by name
43 order by name
44 /
N COUNT(NAME)
A 3
B 1
C 3
D 5 -
How to fetch single row data into multiple columns
Hi Have a cursor
which will have SELECT Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs from OTMaster;
now my cursor has one row of the above columns with this row data I want to insert into other tale as column wise
ex:
my row is like this: Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs
01:00 01:00 01:00 01:00 01:00 01:00 01:00
now I want to insert the above data into table with loop along with weekday
weekday, OTHrs
1 01:00
2 01:00
3 01:00
4 01:00
5 01:00
6 01:00
7 01:00
which type of variable I need to fetch the records, rowtype or tabletype,
plz help methank you for information, and now I am using UNPIVOT below is my query
SELECT * FROM OTCEILINGMASTER
UNPIVOT(OTHOURS FOR WEEK_DAY IN (SUN_CEILING_HRS AS '1',MON_CEILING_HRS AS '2',TUE_CEILING_HRS AS '3',
WED_CEILING_HRS AS '4',THU_CEILING_HRS AS '5',FRI_CEILING_HRS AS '6',SAT_CEILING_HRS AS '7'));
when I am selecting all the columns (select * from OTCEILINGMASTER) then only the above query is executing I want only two columns from the table however my table has 10 columns.
please looking into this -
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. -
Hi,
I have written a CQL query with rows 3 records. In that query is it possible to fetch first record and last record specific field values.
for example,
Column: c1, c2, c3
record1: id1, 2.3, 3.5
record2: id2, 2.3, 3.6
record3: id21, 2.3, 3.7
record3: id25, 2.3, 3.9
I need to get moving average of three rows of c3 and get first record id and last record ids.
output1: id1, id1, avg(c3)=3.5
output2: id1, id2, avg(c3)=3.55
output3: id1, id21, avg(c3)=3.6
output4: id2, id25, avg(c3)=3.733
Please help on above.
Thanks,
SriI have one more question.
The average output is given as input to pattern match processor.
The double differentiation differentiation of first 2 average input data in CQL pattern match is written as:
<view id="FetchRows">
<![CDATA[ istream(select * from mdepthChannel)
]]>
</view>
<query id="ExampleQuery">
<![CDATA[ select *
from FetchRows
MATCH_RECOGNIZE (
Measures
v1.wellUid as wellUid,
v1.arrivalTime as arrivalTime,
v1.wellboreUid as wellboreUid,
v1.mdepthAverage as mdepthAverage,
v1.wopAverage as wopAverage,
v2.mdepthAverage as v2mdepthAverage,
v2.wopAverage as v2wopAverage,
v3.mdepthAverage as v3mdepthAverage,
v3.wopAverage as v3wopAverage,
getCalculateDerivative(v2.mdepthAverage,getCalculateDerivative(v1.mdepthAverage,v1.wopAverage,v2.mdepthAverage,v2.wopAverage),v3.mdepthAverage,getCalculateDerivative(v2.mdepthAverage,v2.wopAverage,v3.mdepthAverage,v3.wopAverage)) as derValue
ALL MATCHES
PATTERN (v1 v2 v3)
DEFINE
v3 as (getCalculateDerivative(v2.mdepthAverage,getCalculateDerivative(v1.mdepthAverage,v1.wopAverage,v2.mdepthAverage,v2.wopAverage),v3.mdepthAverage,getCalculateDerivative(v2.mdepthAverage,v2.wopAverage,v3.mdepthAverage,v3.wopAverage)) <= 0.0)
) as T
]]>
</query>
Where "getCalculateDerivative" is the java function returns slope of straight line.
The output of this query returns correct data till 7th record after that it repeats 6nd record.
That 8th record is the same as 6th record data.
Why that 8th record is the 6nd record repeats.
The desired output is same as input record if pattern matches.
Please help on this.
Thanks,
Sri
Edited by: 897694 on Mar 27, 2012 2:15 AM -
How to return one ROW with Multiple value seperated by Colon in a SQL Query
Hi,
I have a SQL query as mentioned.
select deptno
from deptI want to mofidfy this query, so that this should return me department list with colon delimeted in one ROW.
10:20:30:40.......Thanks,
DeepakIn 10g:
select rtrim(xmlagg(xmlparse(content deptno || ':')).getstringval(), ':') data
from dept;
DATA
10:20:30:40with apologies for the abuse of XML...
Maybe you are looking for
-
DPM (ID 30101 Détails : data error ( cyclic redundancy check) 0x80070017)
Dear all, We are running DPM 2010 with a virtual tape library "firestreamer" Sometime for no reason we get this error on DPM ( none on firestreamer ): DPM a rencontré une erreur critique lors d'une opération d'E/S sur la bande Travail-LT-1Jours-Copie
-
Airport Express choppy when using multiple speakers
Had a big New Year's party. I setup my recent Mac mini in one room wired directly to a stereo, and my Airport Express (latest model that looks like a white Apple TV) in another room connected to another stereo. I use the Airport Express a lot and it
-
Mpeg 2 to mpeg1 via Compressor 2
Here's the situation: Client calls, needs versions of their TV spots for a powerpoint presentation. I'm given the DVD originals and asked to provide it. I: 1) Rip the spots via Cinematize to Quicktime files with an mpeg2 video track and an integer (b
-
New Project, Formatting Issues
Okay so I'm going to try to explain this as best as possible because it can be quite confusing. Now I made a youtube background in which I downloaded a template which basically showed all the boxes in the right spot, when I added all the images, resi
-
Extension manager keeps crashing!
Had to reinstall Yosemite and since then extension manager keeps crashing. I am using a Mac and have installed the latest version of Extension Manager for CS 5.5. Please help! Yosemite version 10.10.1. Cannot install any of my extensions