我有这个 mysql 代码女巫工作得很好
SELECT uid , MAX(value) AS bidvalue FROM auction
WHERE pid = '$pid' and max_bid=0
GROUP BY uid
ORDER BY bidvalue DESC
LIMIT 1
如何在 users.id=auction.uid 上的用户表中加入此选择?
谢谢
我在这里看不到任何魔法:
SELECT uid, users.name, MAX(value) AS bidvalue
FROM auction
INNER JOIN users ON users.id = auction.uid
WHERE pid = '$pid' and max_bid=0
GROUP BY uid
ORDER BY bidvalue DESC
LIMIT 1
您可以使用连接,您的查询可能看起来像
SELECT uid, users.name, MAX(value) AS bidvalue
FROM auction
INNER JOIN users ON users.id = auction.uid
WHERE pid = '$pid' and max_bid=0
GROUP BY uid
ORDER BY bidvalue DESC
LIMIT 1
或者
SELECT uid, users.name, MAX(value) AS bidvalue
FROM auction
OUTER JOIN users ON users.id = auction.uid
WHERE pid = '$pid' and max_bid=0
GROUP BY uid
ORDER BY bidvalue DESC
LIMIT 1