SQL语句查询记录
1、查询一张表两个datetime字段,时间相差的秒数,条件:具体到某一天and差值大于400s,并且按照差值排序。
SELECT end_time,start_time,UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time)from XXX WHERE date_format(start_time,'%Y-%m-%d')='2019-04-12' AND UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time)>=400 ORDER BY UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time) DESC
2、查询一张表两个datetime字段,时间相差的秒数的平均值,条件:具体到某一天。
SELECT AVG(UNIX_TIMESTAMP(end_time))-AVG(UNIX_TIMESTAMP(start_time)) from XXX WHERE date_format(start_time,'%Y-%m-%d')='2019-04-12'