我正在尝试使用listings
表中最高bidder_ID
的{{1}}表的buyer_ID列自动更新。我的问题是......如何从bids
表中获取与bid_listing
相关的listing_ID
?
我当前的事件查询:
listing
出价架构
CREATE EVENT updateAuction
ON SCHEDULE EVERY 1 MINUTE
DO
SET buyer_ID = (SELECT MAX(bidder_ID) FROM bids WHERE bid_listing = (Need each listing_ID from the listings table here))
FROM listings
WHERE list_expires < now()
AND buyer_ID = NULL
列表架构
bid_ID bid_listing bidder_ID bid_amount
答案 0 :(得分:1)
基于代码示例和您的“出价表中出价最高的ID”的声明
我认为你需要的是 UPDATE JOIN
In [18]: df.Name.tolist()
Out[18]: [u'Christine', u'Alex', u'Brian', u'Thomas', u'Tom']
In [19]: df.Name.str.encode('latin-1', 'ignore').tolist()
Out[19]: ['Christine', 'Alex', 'Brian', 'Thomas', 'Tom']
以下是 UPDATE JOIN 的另一个示例,使用SUB QUERIES获取出价金额最高的bidder_id。
Update listings set
buyer_id = table2.max_bidder
From listings table1
Inner Join ( Select bids.listing_ID
, max(bids.bidder_ID) as max_bidder
From bids
Group by listing_ID ) table2
on ( table1.listing_ID = table2.listing_ID )
WHERE list_expires < now()
AND buyer_ID is NULL
我希望它有所帮助
此致