gpt4 book ai didi

sql - 帮助创建一个相当复杂的sql语句

转载 作者:行者123 更新时间:2023-11-29 01:15:18 26 4
gpt4 key购买 nike

大家好,我不太确定如何用 google 搜索的形式来描述它,所以我决定来这里看看你们是否可以提供帮助。基本上,我想知道如何将以下伪 SQL 转换为实际的 mysql 查询:

Select one random row 
from `posts`
where (the user's id, which is supplied by the script) is not found in the `votes` table
with a post id of (the selected post's id).

如能提供帮助,万分感谢。

最佳答案

像这样:

SELECT *
FROM Posts
WHERE Posts.ID NOT IN (
SELECT Votes.PostID FROM Votes WHERE Votes.UserID=@UserID
)
ORDER BY Rand()
LIMIT 1

关于sql - 帮助创建一个相当复杂的sql语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2150537/

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