Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Return highest value from each day
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Nice SOP
Starting Member

1 Posts

Posted - 07/09/2013 :  16:29:31  Show Profile  Reply with Quote
I have a database containing server populations at 5 minute intervals(logged as timestamp). I want to return a chart containing only the highest server poulation from each day. How would I code this task?

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/09/2013 :  16:34:06  Show Profile  Reply with Quote
quote:
Originally posted by Nice SOP

I have a database containing server populations at 5 minute intervals(logged as timestamp). I want to return a chart containing only the highest server poulation from each day. How would I code this task?

SELECT
	*
FROM
(
	SELECT *,
		ROW_NUMBER() OVER (PARTITION BY Date ORDER BY POPULATION DESC) AS RN
	FROM
		YourServerPopulationTable
) s WHERE RN = 1;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 07/10/2013 :  03:13:44  Show Profile  Reply with Quote

SELECT *
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY DATEDIFF(dd,0,[timestamp]) ORDER BY POPULATION DESC) AS Seq,*
FROM Table 
)t
WHERE Seq=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 07/10/2013 :  03:24:18  Show Profile  Visit SwePeso's Homepage  Reply with Quote
A timestamp is NOT a datatype used for temporal data. It is a version mechanism.
Can you please clarify your table structure?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000