我有User表如下:
Userid| Username |city| state
这里userid是主键 还有一个招标表
Userid|seller|iid|starttime|bidtime|bidprice
此处用户ID,卖家,iid构成主键
我想编写一个sql查询,以便显示整体出价最多的人的用户ID和名称。我写了如下查询:
select u.userid,u.uname from user1 u, bid b where u.userid=b.bidder and
b.bidder=(select max(c) from (select count(*) as c, bidder from bid group by bidder));
但在这种情况下,内部选择显示的最大值不满足给定条件。我想要一些帮助来解决这个问题
答案 0 :(得分:0)
这似乎是一种更简单的方法。
SELECT TOP 1 u.*
FROM User1 u
JOIN bid b ON (u.userid=b.bidder)
ORDER BY Count(b.*)
答案 1 :(得分:0)
select userid, uname from user1
where userid in
(select bidder from bid group by bidder having count(bidder) =
(select max(c) from (select count(*) as c, bidder from bid group by bidder)));