我想要显示每个产品的独特出价者

时间:2015-12-05 08:11:28

标签: mysql

我有四张表1) Users 2) Products 3) Auctions 4) biddetails。用户和产品是主表和拍卖表中的产品ID就在那里。而biddetail表所有关键都有productid,userid和auctionid。

问题:我希望看到独特竞标者的每一件产品。

我的查询如下:

SELECT `p`.*, `a`.`id` as Auctionid, `a`.`enddate` as Enddate, `a`.`startdate` as Startdate, `a`.`bidprice` as Bidprice, `a`.`bidtype` as Bidtype, `a`.`starttime` as Starttime, `a`.`endtime` as Endtime, (SELECT  username
FROM  (select bid_price,u.username from biddetail as b join users as u on b.userid=u.id where b.auctionid=Auctionid   group by b.bid_price,b.auctionid having count(b.bid_price)=1  order by b.bid_price asc Limit 0,1) t1 ) as Username FROM (`products` p) JOIN `auctions` a ON `a`.`productid`=`p`.`id` LEFT OUTER JOIN `biddetail` b ON `b`.`auctionid`=`a`.`id`
 WHERE `a`.`status` = '0' AND `a`.`enddate`> '".$date."' AND `a`.`bidtype` = '1' GROUP BY `a`.`id` ORDER BY `a`.`id` desc

0 个答案:

没有答案