Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hii have this query:SELECT title, subtitle, publication_date ,RANK() OVER (ORDER BY credits) AS 'Rank'FROM pressreleases where publication_date > getdate() and it returns for example:Title | Subtitle | Publication_date | Rank test1 test1 11-05-2009 1test2 test2 11-05-2009 2test3 test3 12-05-2009 3test4 test4 12-05-2009 4But what i need is to get the rank by day so it must be like this:Title | Subtitle | Publication_date | Rank test1 test1 11-05-2009 1test2 test2 11-05-2009 2test3 test3 12-05-2009 1test4 test4 12-05-2009 2Thank you!
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2009-05-10 : 17:08:00
Use partition by ... to say where it has to start over with value 1No, you're never too old to Yak'n'Roll if you're too young to die.
SELECT title, subtitle, publication_date,Row_Number() OVER (partition by dateadd(dd,0, datediff(dd,0,PublicationDate)) ORDER BY credits) AS 'Rank'FROM pressreleases where publication_date > getdate()
Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881