Question

i have problems with this query. It shall return the max temperature of the day but it returns empty. what have i done wrong?

SELECT * FROM tempdat WHERE date( tdate ) = curdate( ) AND temperature = ( SELECT max( temperature ) FROM tempdat ) ;

Was it helpful?

Solution

Rather use:

SELECT 
       convert(datetime, convert(varchar(12), tdate ))  AS DayOfTemp
       ,max(temperature)                                   AS MaxTemp
FROM 
    tempdat 
WHERE 
    convert(datetime, convert(varchar(12), tdate )) = convert(datetime, convert(varchar(12, curdate( ) )) 
group by 
    convert(datetime, convert(varchar(12), tdate ))

OTHER TIPS

Your subquery returns the overall maximum of the data - not of the day, you need something like:

select max(temperature) from tempdat group by tdate having tdate = curdate()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top