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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help with query

Author  Topic 

peteoc
Starting Member

14 Posts

Posted - 2008-01-21 : 06:15:15
I'm getting confused with how to perform a query. Maybe someone can help :)

I have a table with the following fields:

id - int
name - varchar(255)
value - int
date - datetime

As an example I have the following data in this table


1,cooker,1,21 jan 2008 11:00:00
2,cooker,1,21 jan 2008 12:00:00
3,temp,300,21 jan 2008 11:00:00
4,temp,450,21 jan 2008 12:00:00
5,cooker,0,21 jan 2008 14:00:00
6,temp,16,21 jan 2008 15:00:00


I would like to be able to get the min value of temp while cooker = 1. I'm confused as to how to go about this, I have tried creating a view but I'm stuck :(

thanks in advance!!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-21 : 06:22:24
Something similar to
SELECT Col1, Col2
FROM (
SELECT Col1, Col2, ROW_NUMBER() OVER (PARTITION BY Col3 ORDER BY Col4 DESC) AS RecID
FROM Table1 WHERE Col5 IS NULL
) AS d
WHERE RecID = 1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -