GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  Sybase
Go To First  |  Previous Question  |  Next Question 
 Sybase  |  Question 47 of 64    Print  
How to find out the maximum sales of an item for each sales man.
The table consists sales_man, item, sales columns,
each sales man will have the different sales values for different items.
here I have to find out for every sales man, which item he sold maximum

  
Total Answers and Comments: 3 Last Update: September 09, 2009     Asked by: Bob 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 29, 2007 12:10:26   #1  
Mak        

RE: How to find out the maximum sales of an item for e...

First you have to ask two questions -

Assuming the given table is (sp item Q) --- sp is sales person id Q is quantity sold for that item.

a) are there duplicate rows which means we will need to sum the quantity first.
b) what happens if a sales person sold more than one item with the SAME maximum quantity ? ie. John's top sale was 500 however he sold 500 computers and also sold 500 laptops. Does the report show only one item or both items and if only one then which one should be shown (ie. what is the criteria). I am assuming that both items should be shown.

Here is the query

select sp item sum(Q) as TQ
from <table>
into #t
group by sp item

select sp item TQ
from #t a
where a.TQ (select max(TQ) from #t b where b.sp a.sp)



if you want everything in one query then here is the one --



select a.sp a.item a.TQ
from (select sp item sum(Q) as TQ
from <table>
group by sp item ) a
where a.TQ (select max(TQ) from #t b where b.sp a.sp)



 
Is this answer useful? Yes | No
September 08, 2008 06:33:52   #2  
swadheengupta Member Since: June 2008   Contribution: 2    

RE: How to find out the maximum sales of an item for each sales man.The table consists sales_man, item, sales columns, each sales man will have the different sales values for different items.here I have to find out for every sales man, which item he sold
Assuming that both the items are required to be shown if two or more items are sold of same quantity. The query is :-

select sales_man item sales from table where (sales_man sales) in
(select sales_man max(sales) from table group by sales_man);

 
Is this answer useful? Yes | No
September 09, 2009 16:39:34   #3  
nagaraju_p Member Since: September 2009   Contribution: 3    

RE: How to find out the maximum sales of an item for each sales man.The table consists sales_man, item, sales columns, each sales man will have the different sales values for different items.here I have to find out for every sales man, which item he sold
select a.sales_person a.item a.TotalQuantity
FROM (select b.sales_person b.item SUM(b.InvAmount ) as TotalQuantity from sales_data b
Group by b.sales_person b.item)as a
GROUP BY a.sales_person
HAVING a.TotalQuantity MAX(a.TotalQuantity )

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape