avg returns null

2

I have a query that returns the average of 2 columns of type float, the thing is to change the date from date to datetime to be able to insert it with the time and now the query does not work, I return null in both columns

the table is:

create table mediciones(
    id int  not null primary key AUTO_INCREMENT,
    temperatura float not null,
    humedad float not null,
    idvinedo int not null,
    fecha datetime not null,
    FOREIGN KEY (idvinedo) REFERENCES vinedo(id));

and the query is:

SELECT AVG(temperatura) as temperatura, AVG(humedad) as humedad from
mediciones WHERE idvinedo=1 and fecha='2018-09-26'

the database gives me the following message when I run the query:

  

The current selection does not contain a single column.

I hope you can help me

    
asked by zhet 27.09.2018 в 04:07
source

1 answer

0

Null returns, because now it is datetime and you are including only the date as part of filtering, if what is really obeneter the average indicating the day, regardless of the time, you can modify your query:

    SELECT AVG(temperatura) as temperatura, AVG(humedad) as humedad from
mediciones WHERE idvinedo=1 and DATE(fecha)='2018-09-26';

For the case in which you comment

  

The current selection does not contain a single column.

I have not been able to reproduce it, the query is correct.

    
answered by 14.10.2018 в 23:11