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

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

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

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

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

  1. 573 1
dluptydi

dluptydi1#

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

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

相关问题