【问题标题】:mysql subquery in single table单表中的mysql子查询
【发布时间】:2010-08-04 03:26:57
【问题描述】:

“条目”表中有 2 列:一个非唯一 ID 和一个日期戳 (YYYY-MM-DD)。我想选择“今天插入的所有以前从未输入过的条目ID。”

我一直在尝试使用子查询,但我认为我没有正确使用它,因为它们都是在同一张表上执行的。有人可以用正确的选择语句帮助我吗?如果需要,我可以提供更多详细信息。

【问题讨论】:

  • 你应该注意你的表结构。

标签: select mysql join subquery


【解决方案1】:

免责声明:我现在无法访问 mysql 数据库,但这应该会有所帮助:

select
  e.id
from
   entries e
where
   e.date = curdate() and
   e.id not in
     (select id from entries e2 where e2.date < e.date)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 2020-02-11
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    相关资源
    最近更新 更多