您使用哪种MySQL语言?如果使用MySqlDialect或MySql5Dialect,则可以使用以下命令:
SELECt count(history.city_id) FROM history where timediff(now(), history.ts) < '720' and history.city_id = id
或定义新的hibernate功能
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)" ) ); }}
查询:
History.ts < date_sub_interval(now(), 30, DAY)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)