Home » SQL & PL/SQL » SQL & PL/SQL » how to write this query
how to write this query [message #399421] Wed, 22 April 2009 02:55 Go to next message
LAZYGIRL
Messages: 34
Registered: May 2006
Member
i have this query


SQL> SELECT t.expqtyrmn,
2 t.expcde
3 FROM bksdba.kexpbokt t
4 WHERE t.expbok = 'UobBkLaw103'
5 AND t.expqtyrmn > 0
6 AND t.exploc = 'S'
7 /

EXPQTYRMN EXPCDE
--------- ------
3 000006
6 000013
12 000001

and i want the result to select the max qty and code form that query such this result

EXPQTYRMN EXPCDE
--------- ------
12 000001

any help




Re: how to write this query [message #399426 is a reply to message #399421] Wed, 22 April 2009 03:03 Go to previous messageGo to next message
danish_fsd@yahoo.com
Messages: 38
Registered: February 2008
Location: Pakistan
Member
Use ROW_NUMBER function with subquery. Read following

http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions144.htm

Regards

Danish
Re: how to write this query [message #399427 is a reply to message #399421] Wed, 22 April 2009 03:04 Go to previous messageGo to next message
Michel Cadot
Messages: 64117
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Post a working Test case: create table and insert statements along with the result you want with these data.

Regards
Michel
Re: how to write this query [message #399440 is a reply to message #399426] Wed, 22 April 2009 03:51 Go to previous messageGo to next message
elaiyavel
Messages: 114
Registered: April 2008
Senior Member
Try using

SELECT t.expqtyrmn,
2 t.expcde
3 FROM bksdba.kexpbokt t
4 WHERE t.expbok = 'UobBkLaw103'
5 AND t.expqtyrmn > 0
6 AND t.exploc = 'S'
order by expqtyrmn desc; Smile
Re: how to write this query [message #399441 is a reply to message #399440] Wed, 22 April 2009 03:58 Go to previous message
Michel Cadot
Messages: 64117
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Try to read and follow what I posted.

Regards
Michel
Previous Topic: range partitioning
Next Topic: How to remove NOT NULL constraint
Goto Forum:
  


Current Time: Tue Dec 06 04:45:37 CST 2016

Total time taken to generate the page: 0.10166 seconds