Unix Technical Forum

Data with Max Qty and Date ?

This is a discussion on Data with Max Qty and Date ? within the Oracle Miscellaneous forums, part of the Oracle Database category; --> hi all, I am really do not know how to get this. Tried all types of queries. The requirement ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-07-2008, 09:58 PM
captain
 
Posts: n/a
Default Data with Max Qty and Date ?

hi all,

I am really do not know how to get this. Tried all types of queries.
The requirement is as below

itemid maxqty Mdate (date is when the max qty went out)
001 5 5/1/2004
002 2 5/10/2004

The actual table has all transaction data as below.
itemid qty date
001 5 5/1/2004
001 3 5/2/2004
001 3 5/3/2004
001 2 5/4/2004
002 0 5/1/2004
......
002 2 5/10/2004

one query is
select itemid,max(qty) from mTran

with the above require which date it occurred.

Please help

Cap2010
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-07-2008, 09:59 PM
Ed prochak
 
Posts: n/a
Default Re: Data with Max Qty and Date ?

captain_2010@yahoo.com (captain) wrote in message news:<27aae5ab.0407272342.4d8e5bb5@posting.google. com>...
> hi all,
>
> I am really do not know how to get this. Tried all types of queries.
> The requirement is as below
>
> itemid maxqty Mdate (date is when the max qty went out)
> 001 5 5/1/2004
> 002 2 5/10/2004
>
> The actual table has all transaction data as below.
> itemid qty date
> 001 5 5/1/2004
> 001 3 5/2/2004
> 001 3 5/3/2004
> 001 2 5/4/2004
> 002 0 5/1/2004
> .....
> 002 2 5/10/2004
>
> one query is
> select itemid,max(qty) from mTran
>
> with the above require which date it occurred.
>
> Please help
>
> Cap2010


Think Relational.

the query "select itemid,max(qty) from mTran" returns rows and
columns, ie a table. Use that to go back to your original table and
get the result you want. (The term for this, if you want to look it
up, is an IN-LINE VIEW.)

Glad to see you found the c.d.o.misc group.

Ed
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-07-2008, 09:59 PM
Michel Cadot
 
Posts: n/a
Default Re: Data with Max Qty and Date ?


"captain" <captain_2010@yahoo.com> a écrit dans le message de
news:27aae5ab.0407272342.4d8e5bb5@posting.google.c om...
> hi all,
>
> I am really do not know how to get this. Tried all types of queries.
> The requirement is as below
>
> itemid maxqty Mdate (date is when the max qty went out)
> 001 5 5/1/2004
> 002 2 5/10/2004
>
> The actual table has all transaction data as below.
> itemid qty date
> 001 5 5/1/2004
> 001 3 5/2/2004
> 001 3 5/3/2004
> 001 2 5/4/2004
> 002 0 5/1/2004
> .....
> 002 2 5/10/2004
>
> one query is
> select itemid,max(qty) from mTran
>
> with the above require which date it occurred.
>
> Please help
>
> Cap2010


Try this:

select itemid, quantity, mdate
from (select itemid, qty, mdate,
rank() over (partition by itemid order by qty desc) rn
from mtran)
where rn=1
/

--
Regards
Michel Cadot


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-07-2008, 10:05 PM
Ashwin
 
Posts: n/a
Default Re: Data with Max Qty and Date ?

this also works,

select * from mtran where
(itemid,qty) in (select itemid,max(qty) from mtran group by itemid)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:31 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com