Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Top 10 products by Month
Top 10 products by Month
Rate Topic
Display Mode
Topic Options
Author
Message
Bulelani M
Bulelani M
Posted Wednesday, February 13, 2013 11:57 PM
Valued Member
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 4:22 AM
Points: 63,
Visits: 257
Hello
Can anyone help me with this below.
Jan 2010 2011 2012
course name course name course name
course name course name course name
course name course name course name
course name course name course name
course name course name course name
Feb 2010 2011 2012
course name course name course name
course name course name course name
course name course name course name
course name course name course name
course name course name course name
Post #1419827
Jason-299789
Jason-299789
Posted Thursday, February 14, 2013 12:12 AM
SSC Eights!
Group: General Forum Members
Last Login: Friday, May 03, 2013 5:35 AM
Points: 803,
Visits: 2,122
If you want the Top 10 Items per month then a Ranking function (RANK(), ROW_NUMBER()) is going to be the best way to move.
However without sample DDL and Input data as well as out put data its difficult to advise on the best solution.
_________________________________________________________________________
SSC Guide to Posting and Best Practices
Post #1419833
Bulelani M
Bulelani M
Posted Thursday, February 14, 2013 1:02 AM
Valued Member
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 4:22 AM
Points: 63,
Visits: 257
I got what I wanted but now I also want it by year.
Here is the code below
;WITH MonthCTE(m) AS
(SELECT 1 m
UNION ALL
SELECT m+1
FROM monthCTE
WHERE m < 12
)
SELECT m[Month]
,t.*
FROM MonthCTE
CROSS Apply
(
SELECT TOP 20
YEAR(ah.enrllmnt_prcssd_dt) [Year]
,p.code
,p.full_name
,CAST(SUM(CASE
WHEN e.payment_type = 1 THEN e.cash / 100
ELSE (1.00 * IsNull(e.installment, 0)
/ 100.00 * IsNull(e.payment_months, 0)) + (1.00 *
IsNull(e.deposit,
0) / 100.00)
END) AS decimal) AS Gev
FROM enrollment AS e
INNER JOIN action_history AS ah
ON ah.action_history_id = e.action_history_id
INNER JOIN product AS p
ON p.product_id = e.product_id
WHERE (
month(ah.enrllmnt_prcssd_dt) BETWEEN 1 AND 12
)
AND (ah.enrllmnt_prcssd_dt >= '2010-01-01' )
AND (ah.enrllmnt_prcssd_dt < '2011-01-01' )--AND (p.code IN (@Prod_code) )
AND (e.status = 2 )
AND (e.brand_id IN (2) )
GROUP BY
YEAR(ah.enrllmnt_prcssd_dt)
,--month(ah.enrllmnt_prcssd_dt),
p.code
,p.full_name
ORDER BY
--YEAR(ah.enrllmnt_prcssd_dt),
--month(ah.enrllmnt_prcssd_dt),
Gev
DESC
) t
Post #1419853
anthony.green
anthony.green
Posted Thursday, February 14, 2013 1:28 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
Please post table definitions, sample data and expected outcome based on the sample data as per the second link in my signature.
With that, we will be able to help you better with your query.
Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1
&
Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger
Post #1419859
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.