Hi Friends,
The list of customer's was billed on 01-apr-2011
custname products value bill_date bill_no
ram Milk 25 01-apr-2011 25
ram Perfume 225 01-apr-2011 25
sam Egg 50 01-apr-2011 26
sam Medicine 125 01-apr-2011 26
now i wanna to extract the maximum billed value from above and display on my result like
custName products Max_sales billed billno
ram Perfume 225 01-apr-2011 25
sam Medicine 125 01-apr-2011 26
how to write code for these scenario?
do the need full
thanks
rocky

Masoud DaneshPour2 reputationPosted Jan 8, 2014, 9:04 PM EST
Select Top 2 * from YourTableName Order By Max_sales desc
the "top 2" guy returns the first 2 row that has max value after ordering
Rocky RockyRank #7,391 · 242 reputationPosted Jan 8, 2014, 9:23 PM EST
Kiran Kumar TalikotiRank #814 · 2.8K reputationPosted Jan 8, 2014, 9:27 PM EST
Check this Query Hope this Helps you
Rocky RockyRank #7,391 · 242 reputationPosted Jan 8, 2014, 9:47 PM EST
Bill no products price Billed_date cust_det
25 Milk 25 01-Apr-2013 ram
Perfume 225 01-Apr-2013 ram
26 EGG 50 01-Apr-2013 sam
Medicine 125 01-Apr-2013 sam
like lacks of records are there.
My expecting O/p is:
Bill no products SALES Billed_date cust_det
25 Perfume 225 01-Apr-2013 ram
26 Medicine 125 01-Apr-2013 sam
Here i wanna display the maximum amount product only display on it to neglect other products how to that?
Hanook159 reputationPosted Jan 9, 2014, 2:05 AM EST
Khan Abrar AhmedRank #778 · 3K reputationPosted Jan 14, 2014, 12:05 AM EST
DECLARE @t AS TABLE(custname VARCHAR(6),products VARCHAR(255), VALUE INT,bill_date DATE, bill_no INT)
INSERT INTO @t VALUES
('ram' , 'Milk' , 25 , '01-apr-2011' , 25),
('ram', 'Perfume' , 225 , '01-apr-2011' , 25),
('sam' , 'Egg', 50 , '01-apr-2011' , 26),
('sam' , 'Medicine' , 125 , '01-apr-2011' , 26)
select bill_no, products, VALUE as SALES, bill_date, custname
from (select *, row_number() over(partition by bill_no order by VALUE desc) RowNumber FROM @t) t
WHERE RowNumber=1