gpt4 book ai didi

mysql - 无论如何要优化以下查询?

转载 作者:太空宇宙 更新时间:2023-11-03 10:51:40 24 4
gpt4 key购买 nike

我在数据库帐户、产品和用户中有三个表。我编写的以下查询执行时间太长。有没有办法优化下面的查询?

"SELECT accounts.id AS aucID, accounts.product_id, accounts.end_time, accounts.price, accounts.win_id, 
products.id, products.title, products.ratio, users.id , users.username, users.gender, users.email, users.ip
FROM accounts, products, users
WHERE products.id
IN (
SELECT id
FROM products
WHERE accounts.product_id = id
)
AND users.id
IN (
SELECT id
FROM users
WHERE accounts.win_id = id
)
AND accounts.end_time >= '$monday'

AND accounts.end_time < '$sunday'

GROUP BY accounts.end_time"

最佳答案

尝试使用 INNER JOIN

SELECT accounts.id AS aucID,
accounts.product_id,
accounts.end_time,
accounts.price,
accounts.win_id,
products.id,
products.title,
products.ratio,
users.id ,
users.username,
users.gender,
users.email,
users.ip
FROM accounts
INNER JOIN products ON accounts.product_id = products.id
INNER JOIN users ON accounts.win_id = users.id
WHERE accounts.end_time >= '$monday'
AND accounts.end_time < '$sunday'
GROUP BY accounts.end_time

关于mysql - 无论如何要优化以下查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24404016/

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