TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kavitha M
NA
21
6.4k
Get Division wise top customers - Sales Report
Apr 30 2015 5:55 AM
Hi ,
I have sales report which has Last year sales,This year sales with doller value.I have four parameters as
follows Invoice from date,Invoice to date, Division(Multiple selection) and Top Number of customers(int).
Now I return top number of cusotmers for each division. For example if i give 10, then it returns top 10 customers within selected division's customers (total 10 records)
my query is like following :
select top (@TopNoCustomer) a.div,a.custID,a.TY_sales from
(select a.div,a.custID,a.TY_Sales from Table_A a where a.Date between (@Fromdate and @Todate)
and a.div in (@Division)) A Join
(select b.div,b.custID,b.LY_Sales from Table_A b where b.Date between (DATEADD(year, -1, @Fromdate) and DATEADD(year, -1, @Todate))
and a.div in (@Division)) B On A.id = B.id where A.division = B.division
group by a.div , a.custID, a.TY_Sales order by a.TY_Sales desc
Now I want to get the top number of customers for each division. For example if i give 10 then it should return top 10 customer for each selected division (if 4 division selected,then it should return 40 records)
Can anyone give me idea to modify my SQL query to return division wise customer
Thanks in advance
Reply
Answers (
1
)
How will bytes it will take in sql???
Get data - Group by from inner query