如何根据日期时间选择行

时间:2016-12-29 14:58:25

标签: mysql database

我必须选择日期为今天或更高的某些行,我只能选择当前时间前十分钟的寄存器。我怀疑如何用'datetime'类型来做到这一点。下面是查询:

SELECT 
    GROUP_CONCAT(timee.nome_time
        ORDER BY timee.nome_time
        SEPARATOR ' X ') AS nome_time,
    partida.id,
    DATE_FORMAT(partida.data_hora, '%d/%m/%Y %H:%i') AS data_hora,
    partida.tb_cotacao_id
FROM
    tb_partida AS partida,
    tb_time AS timee,
    tb_partida_time AS partidaTime
WHERE
    (partida.id = tb_partida_id
        && timee.id = tb_time_id)
        AND (partida.flag_ativo = 1
        AND partida.flag_cancelado <> 1
        AND partida.flag_finalizado <> 1)
        AND partida.tb_campeonato_id = 11
GROUP BY partida.id

我真的很感激任何帮助。提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用TIME_TO_SEC(TIMEDIFF(now(),<datetime_field>)获取时差并将其转换为秒。超过10分钟就会出现这样的情况

SELECT ... FROM .. WHERE TIME_TO_SEC( TIMEDIFF( now() , tb_time )) > 600 ...

修改

要获得时间比当前时间长10分钟的行,只需反转TIMEDIFF内的参数即可。即,

SELECT ... FROM .. WHERE TIME_TO_SEC( TIMEDIFF(tb_time, now() )) > 600 ...