I have a query and I need to use the result of the query in other query. So, I used "WITH .. As". The problem is that the temporary variable should be integer while it was created in text data-type automatically. How I can change or modify the code to have variable in integer data type.
WITH A as (
SELECT ambtemp,
date_trunc('hour', dt)+
CASE WHEN date_part('minute', dt) >= 30
THEN interval '30 minutes'
ELSE interval '0 minutes'
END as t
FROM temm),
B as(
SELECT ambtemp,t,
max(ambtemp) OVER (PARTITION BY t) as max_temp,
min(ambtemp) OVER (PARTITION BY t) as min_temp
FROM A)
SELECT *
FROM B
WHERE (max_temp - min_temp) <= 0.2
max_temp and min_temp should be built in integer data-type while they are in text format.