gpt4 book ai didi

php - mysql-查询其他表条件PHP

转载 作者:行者123 更新时间:2023-11-30 22:36:23 25 4
gpt4 key购买 nike

我在 mysql 中有一张名为 safespot 的表

+---------+---------------+
| term_id | userid | safe |
+---------+--------|------+
| 1 | 1 | large number, unix timestamp here
| 1 | 2 | large number, unix timestamp here
| 1 | 3 | large number, unix timestamp here
| 1 | 4 | large number, unix timestamp here
+---------+--------+

这是表 users:

+----+-------------+-------------+
| id | userid | cash |
+----+-------------+-------------+
| 1 | 1 | 100000 |
| 2 | 2 | 100000 |
| 3 | 3 | 100000 |
+----+-------------+-------------+

我该怎么做

SELECT * FROM `users` where `userid`=1 and `cash`>= 1000 and " userid do not exist in table safespot" or "if the user exists in the safestop table, check if the current timestamp is higher than the safe colum)

所以基本上做一个查询,如果 safespot 表中不存在 userid 也会返回它,或者如果存在,则时间戳高于 safe_value。

最佳答案

SELECT * FROM users u
LEFT JOIN safespot s ON s.userid = u.userid
WHERE
u.userid = 1
AND u.cash = 1000
AND (s.userid IS NULL OR s.safe > UNIX_TIMESTAMP())

这会返回用户所在的位置

  • safespot 中没有给定用户 ID 的条目,或者
  • safespot 中有一个条目,其 safe 的值大于当前时间戳。

关于php - mysql-查询其他表条件PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32441960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com