gpt4 book ai didi

php - 如何让这 2 个 SQL 查询成为 1

转载 作者:行者123 更新时间:2023-11-29 02:37:17 25 4
gpt4 key购买 nike

表是:user_table(user_id, user_name) , votes_table(id,user_id, vote_date, votes)

$sql = SELECT user_id, sum(votes) AS sumvotes, vote_date 
FROM votes_table
WHERE vote_date > 1279749600
ORDER BY sumvotes DESC
LIMIT 10

$result = query($sql)

foreach user_id in $result
$sql = SELECT user_id, username
FROM user_table u
WHERE u.user_id = user_id
$result2 = query($sql)
somearray.add($result AND $result2)

最佳答案

SELECT user_id, username 
FROM user_table u, (SELECT user_id, sum(votes) AS sumvotes, vote_date
FROM votes_table
WHERE vote_date > 1279749600
ORDER BY sumvotes DESC
LIMIT 10) t
WHERE u.user_id = t.user_id

关于php - 如何让这 2 个 SQL 查询成为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3369797/

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