sql >> Base de Datos >  >> RDS >> Mysql

Anotación de fórmula de Hibernate:funciones MySql:INTERVALO, DÍA

¿Qué dialecto de MySQL usa? Si MySqlDialect o MySql5Dialect puede usar lo siguiente:

SELECT count(history.city_id) FROM history where timediff(now(), history.ts) < '720' and history.city_id = id

O defina una nueva función de hibernación

public class ExtendedMySQL5Dialect extends MySQL5Dialect 
{
        public ExtendedMySQL5Dialect() 
        {
           super();
           registerFunction( "date_sub_interval", new SQLFunctionTemplate( Hibernate.DATE, "date_sub(?1, INTERVAL ?2 ?3)" ) );
           registerFunction( "date_add_interval", new SQLFunctionTemplate( Hibernate.DATE, "date_add(?1, INTERVAL ?2 ?3)" ) );           
        }
}

Consulta:

History.ts < date_sub_interval(now(), 30, DAY)