SQL - 在特定时间(或 ID)后选择新值

发布于 2024-12-15 15:21:57 字数 709 浏览 1 评论 0原文

我需要 PHP 中的 SQL for MySQL。请查看下表:

 | id |       ip       |   time   |
 | -------------------------------|
 | 1    88.207.189.58  1321301482 |
 | 2    76.192.849.84  1321301487 |
 | 3    65.253.192.46  1321301492 |
 | 4    88.207.189.58  1321301522 |
 | 5    12.112.221.22  1321301582 |
 | 6    65.253.192.46  1321301633 |
 | 7    76.192.849.84  1321301657 |
 | 8    76.192.849.84  1321301710 |
 | 9    12.112.221.22  1321301819 |

我需要选择特定时间后新的 IP

例如:我想选择 time=1321301522 之后的行,但它们应该是新的,它们可能不会在该时间之前出现。在这种情况下,唯一有效的 IP 是 12.112.221.22(第 5 行)。

这是行不通的:SELECT ip FROM table_name WHERE time>1321301522,因为它还会列出非新的。在那之前他们可能没有出现过。

提前致谢!!

I need an SQL in PHP for MySQL. Please view the table below:

 | id |       ip       |   time   |
 | -------------------------------|
 | 1    88.207.189.58  1321301482 |
 | 2    76.192.849.84  1321301487 |
 | 3    65.253.192.46  1321301492 |
 | 4    88.207.189.58  1321301522 |
 | 5    12.112.221.22  1321301582 |
 | 6    65.253.192.46  1321301633 |
 | 7    76.192.849.84  1321301657 |
 | 8    76.192.849.84  1321301710 |
 | 9    12.112.221.22  1321301819 |

I need to select the ip's that are NEW after a particular time

Eg: I want to select rows after time=1321301522 but they should be new, they may not appear before that time. In this case the only valid ip would be 12.112.221.22 (row 5).

This wouldn't work: SELECT ip FROM table_name WHERE time>1321301522 because it would also list the non-new ones. They may not have appeared before that time.

Thanks in advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安稳善良 2024-12-22 15:21:57
SELECT ip
FROM myTable
GROUP BY ip
HAVING MIN(time) >= 1321301522
SELECT ip
FROM myTable
GROUP BY ip
HAVING MIN(time) >= 1321301522
双马尾 2024-12-22 15:21:57
SELECT ip from tableName where time > 1321301522 and NOT EXISTS (SELECT ip from tableName where time <= 1321301522 )

不确定这是否是最好的方法,但这是一种方法。

SELECT ip from tableName where time > 1321301522 and NOT EXISTS (SELECT ip from tableName where time <= 1321301522 )

Not sure if this is the best way to do it, but it is one way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文