1
1
123 1232014-11-23 20:13:01
MySQL
123 123, 2014-11-23 20:13:01

How to convert a query to PostgreSQL?

Good day to all. I have a table with fields - (id, temp, hum, date). An entry is added to it every 5 minutes. There is a query that displays temp, hum and date for every hour for the current day. That is, 24 records.

SELECT temp, hum, date 
FROM meteo_temp0 
WHERE DATE(date) = CURDATE() 
GROUP BY EXTRACT(HOUR FROM date) 
ORDER BY EXTRACT(HOUR FROM date)
Help to convert it to PostgreSQL. I am attaching an image of the table for clarity.
Tried like this:
SELECT temp, hum, date 
FROM meteo_temp0 
WHERE DATE(date) = CURRENT_DATE 
GROUP BY EXTRACT(HOUR FROM(date)) 
ORDER BY EXTRACT(HOUR FROM(date))
Gives an error message:
column "meteo_temp0.temp" must appear in the GROUP BY clause or be used in an aggregate function

15e12ac7f03f4e688104681dbef2d052.PNGThanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2014-11-23
@mistergalynsky

use the date_part function
pgcookbook.ru/programming/date_and_time.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question