dbTalk Databases Forums  

any way to get MAX?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss any way to get MAX? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Totti
 
Posts: n/a

Default any way to get MAX? - 01-06-2008 , 01:02 PM









Hi all , i want to get out of the data, the most popular good/month i
have in my data, i figured out that it would be the one having the
maximum sales, so i m using the following formula to see for every
month, and every product, and how much were the sales this month,
now the solution would be if i can get the max amount and it is
therefore the product i need, but how could that be done if i have the
following?
==========================================
select (to_char(salinv_1.inv_date, 'MM'))as "MM",
(to_char(salinv_1.inv_date, 'YY')) as "YY",
(sales_1.prod_code) as "Code",
sum(salpmt_1.amount) as "Total Purchase"
from sales_1,salinv_1, salpmt_1
where salinv_1.code = sales_1.inv_code and
to_char(salpmt_1.pmt_date,'MM-YY') = to_char(salinv_1.inv_date, 'MM-
YY')
group by (sales_1.prod_code),
(to_char(salinv_1.inv_date, 'MM')),
(to_char(salinv_1.inv_date, 'YY'))
order by (to_char(salinv_1.inv_date,'YY'))
=============================================
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.1 345180
01 05 SP-20.2 396957
01 05 SP-20.3 138072
01 05 SP-20.4 138072
01 05 SP-20.5 241626
01 05 SP-20.6 276144
01 05 SP-20.7 276144
02 05 SP-20.1 328445
02 05 SP-20.2 353710
02 05 SP-20.3 151590
02 05 SP-20.4 303180
02 05 SP-20.5 277915
02 05 SP-20.6 378975
02 05 SP-20.7 176855
============================================
while what i need is like so :
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.2 396957
02 05 SP-20.2 353710
============================================
is it possible?
and thank you very much

Reply With Quote
  #2  
Old   
DA Morgan
 
Posts: n/a

Default Re: any way to get MAX? - 01-06-2008 , 03:24 PM






Totti wrote:
Quote:

Hi all , i want to get out of the data, the most popular good/month i
have in my data, i figured out that it would be the one having the
maximum sales, so i m using the following formula to see for every
month, and every product, and how much were the sales this month,
now the solution would be if i can get the max amount and it is
therefore the product i need, but how could that be done if i have the
following?
==========================================
select (to_char(salinv_1.inv_date, 'MM'))as "MM",
(to_char(salinv_1.inv_date, 'YY')) as "YY",
(sales_1.prod_code) as "Code",
sum(salpmt_1.amount) as "Total Purchase"
from sales_1,salinv_1, salpmt_1
where salinv_1.code = sales_1.inv_code and
to_char(salpmt_1.pmt_date,'MM-YY') = to_char(salinv_1.inv_date, 'MM-
YY')
group by (sales_1.prod_code),
(to_char(salinv_1.inv_date, 'MM')),
(to_char(salinv_1.inv_date, 'YY'))
order by (to_char(salinv_1.inv_date,'YY'))
=============================================
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.1 345180
01 05 SP-20.2 396957
01 05 SP-20.3 138072
01 05 SP-20.4 138072
01 05 SP-20.5 241626
01 05 SP-20.6 276144
01 05 SP-20.7 276144
02 05 SP-20.1 328445
02 05 SP-20.2 353710
02 05 SP-20.3 151590
02 05 SP-20.4 303180
02 05 SP-20.5 277915
02 05 SP-20.6 378975
02 05 SP-20.7 176855
============================================
while what i need is like so :
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.2 396957
02 05 SP-20.2 353710
============================================
is it possible?
and thank you very much
Go to this page:
http://www.psoug.org/reference/analytic_functions.html

And look at the following functions:
DENSE_RANK
MAX
RANK
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #3  
Old   
DA Morgan
 
Posts: n/a

Default Re: any way to get MAX? - 01-06-2008 , 03:24 PM



Totti wrote:
Quote:

Hi all , i want to get out of the data, the most popular good/month i
have in my data, i figured out that it would be the one having the
maximum sales, so i m using the following formula to see for every
month, and every product, and how much were the sales this month,
now the solution would be if i can get the max amount and it is
therefore the product i need, but how could that be done if i have the
following?
==========================================
select (to_char(salinv_1.inv_date, 'MM'))as "MM",
(to_char(salinv_1.inv_date, 'YY')) as "YY",
(sales_1.prod_code) as "Code",
sum(salpmt_1.amount) as "Total Purchase"
from sales_1,salinv_1, salpmt_1
where salinv_1.code = sales_1.inv_code and
to_char(salpmt_1.pmt_date,'MM-YY') = to_char(salinv_1.inv_date, 'MM-
YY')
group by (sales_1.prod_code),
(to_char(salinv_1.inv_date, 'MM')),
(to_char(salinv_1.inv_date, 'YY'))
order by (to_char(salinv_1.inv_date,'YY'))
=============================================
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.1 345180
01 05 SP-20.2 396957
01 05 SP-20.3 138072
01 05 SP-20.4 138072
01 05 SP-20.5 241626
01 05 SP-20.6 276144
01 05 SP-20.7 276144
02 05 SP-20.1 328445
02 05 SP-20.2 353710
02 05 SP-20.3 151590
02 05 SP-20.4 303180
02 05 SP-20.5 277915
02 05 SP-20.6 378975
02 05 SP-20.7 176855
============================================
while what i need is like so :
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.2 396957
02 05 SP-20.2 353710
============================================
is it possible?
and thank you very much
Go to this page:
http://www.psoug.org/reference/analytic_functions.html

And look at the following functions:
DENSE_RANK
MAX
RANK
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #4  
Old   
DA Morgan
 
Posts: n/a

Default Re: any way to get MAX? - 01-06-2008 , 03:24 PM



Totti wrote:
Quote:

Hi all , i want to get out of the data, the most popular good/month i
have in my data, i figured out that it would be the one having the
maximum sales, so i m using the following formula to see for every
month, and every product, and how much were the sales this month,
now the solution would be if i can get the max amount and it is
therefore the product i need, but how could that be done if i have the
following?
==========================================
select (to_char(salinv_1.inv_date, 'MM'))as "MM",
(to_char(salinv_1.inv_date, 'YY')) as "YY",
(sales_1.prod_code) as "Code",
sum(salpmt_1.amount) as "Total Purchase"
from sales_1,salinv_1, salpmt_1
where salinv_1.code = sales_1.inv_code and
to_char(salpmt_1.pmt_date,'MM-YY') = to_char(salinv_1.inv_date, 'MM-
YY')
group by (sales_1.prod_code),
(to_char(salinv_1.inv_date, 'MM')),
(to_char(salinv_1.inv_date, 'YY'))
order by (to_char(salinv_1.inv_date,'YY'))
=============================================
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.1 345180
01 05 SP-20.2 396957
01 05 SP-20.3 138072
01 05 SP-20.4 138072
01 05 SP-20.5 241626
01 05 SP-20.6 276144
01 05 SP-20.7 276144
02 05 SP-20.1 328445
02 05 SP-20.2 353710
02 05 SP-20.3 151590
02 05 SP-20.4 303180
02 05 SP-20.5 277915
02 05 SP-20.6 378975
02 05 SP-20.7 176855
============================================
while what i need is like so :
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.2 396957
02 05 SP-20.2 353710
============================================
is it possible?
and thank you very much
Go to this page:
http://www.psoug.org/reference/analytic_functions.html

And look at the following functions:
DENSE_RANK
MAX
RANK
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #5  
Old   
DA Morgan
 
Posts: n/a

Default Re: any way to get MAX? - 01-06-2008 , 03:24 PM



Totti wrote:
Quote:

Hi all , i want to get out of the data, the most popular good/month i
have in my data, i figured out that it would be the one having the
maximum sales, so i m using the following formula to see for every
month, and every product, and how much were the sales this month,
now the solution would be if i can get the max amount and it is
therefore the product i need, but how could that be done if i have the
following?
==========================================
select (to_char(salinv_1.inv_date, 'MM'))as "MM",
(to_char(salinv_1.inv_date, 'YY')) as "YY",
(sales_1.prod_code) as "Code",
sum(salpmt_1.amount) as "Total Purchase"
from sales_1,salinv_1, salpmt_1
where salinv_1.code = sales_1.inv_code and
to_char(salpmt_1.pmt_date,'MM-YY') = to_char(salinv_1.inv_date, 'MM-
YY')
group by (sales_1.prod_code),
(to_char(salinv_1.inv_date, 'MM')),
(to_char(salinv_1.inv_date, 'YY'))
order by (to_char(salinv_1.inv_date,'YY'))
=============================================
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.1 345180
01 05 SP-20.2 396957
01 05 SP-20.3 138072
01 05 SP-20.4 138072
01 05 SP-20.5 241626
01 05 SP-20.6 276144
01 05 SP-20.7 276144
02 05 SP-20.1 328445
02 05 SP-20.2 353710
02 05 SP-20.3 151590
02 05 SP-20.4 303180
02 05 SP-20.5 277915
02 05 SP-20.6 378975
02 05 SP-20.7 176855
============================================
while what i need is like so :
MM YY Code Total Purchase
-- -- --------------- --------------
01 05 SP-20.2 396957
02 05 SP-20.2 353710
============================================
is it possible?
and thank you very much
Go to this page:
http://www.psoug.org/reference/analytic_functions.html

And look at the following functions:
DENSE_RANK
MAX
RANK
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.