从db中选择数据以查找条件中的datediff

时间:2016-03-27 02:30:44

标签: php mysql

有人帮帮我,伙计们?我有这样的查询:

SELECT id_instansi, nama_file, valid_date,
    TIMESTAMPDIFF(DAY, valid_date, CURDATE()) AS selisih
FROM tbl_attachment

enter image description here

我的问题是我只想显示“ selisih ”值= -4的行,而不是全部。 任何人都可以告诉我如何编写正确的查询来解决我的问题吗?

2 个答案:

答案 0 :(得分:2)

SELECT id_instansi, nama_file, valid_date,
    TIMESTAMPDIFF(DAY, valid_date, CURDATE()) AS selisih
FROM tbl_attachment
WHERE
    selisih = -4

答案 1 :(得分:-1)

SELECT id_instansi, nama_file, valid_date, TIMESTAMPDIFF(DAY, valid_date, CURDATE()) AS selisih FROM tbl_attachment 
**WHERE** TIMESTAMPDIFF(DAY, valid_date, CURDATE())=-4