I want 3 different columns cold days,hot days, and normal days
cold days => temperature less than 50 degrees hot days => temperature greater than 90 degrees normal days -> normal days => temperature between 50 -90 degrees
All these come from the same table and the only thing that changes the query is the where clause. How would I assign the where clause to each column??
This is what I have so far... but it doesn't seem right?
select temperatures.temp as "cold days",temperatures.temp as "hot days",temperatures.temp as "normal days" from temperatures where (temperature < 50) and (temperature > 90) and (temperature between 50 and 90)
SELECT SUM(CASE WHEN Col1 < 50 THEN 1 ELSE 0 END) AS ColdDays,
SUM(CASE WHEN Col1 BETWEEN 50 AND 90 THEN 1 ELSE 0 END) AS NormalDays,
SUM(CASE WHEN Col1 > 90 THEN 1 ELSE 0 END) AS HotDays
FROM Table1
SELECT CASE WHEN Temp < 50 THEN Temp ELSE NULL END AS ColdDays,
CASE WHEN Temp BETWEEN 50 AND 90 THEN Temp ELSE NULL END AS NormalDays,
CASE WHEN Temp > 90 THEN Temp ELSE NULL END AS HotDays
FROM Temperatures