如何在bash中压缩sql查询的输出

7kjnsjlb  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(376)

如何将此sql查询的输出缩减为1或0?

SELECT 
object_id,
IF (last_scan_date + INTERVAL 60 MINUTE > NOW(), 1, 0) AS download_correct
FROM `git_download_server`
WHERE object_id="573"

当我从bash运行它时,我的实际输出是(我只需要状态代码1或0):

573    1
dluptydi

dluptydi1#

MySQL 自动将条件求值为1或0,这样就可以不用 object_idselect . 添加 distinct 如果每行有多行 object_id ,但只希望输出中有一行。

SELECT last_scan_date + INTERVAL 60 MINUTE > NOW() AS download_correct
FROM `git_download_server`
WHERE object_id="573";

相关问题