带有父参数的 SQL 嵌套查询
我需要编写该场景的查询,但我失去了编写它的能力。
假设有两个表 Items 和 Bid。通过某种过滤器选择项目
SELECT i.* FROM Items i WHERE i.Id = 2
现在有一个投标表,其中包含“ItemId”列,用于将项目链接到投标。现在我想要所有项目的数据包含 HighestBid、LowestBid 和 TotalBids,我正在尝试此操作,但它不起作用。
SELECT i.*, hal.*
FROM Items i, (SELECT MAX(b.OfferAmount), MIN(b.OfferAmount), COUNT(b.*) FROM Bids b WHERE b.ItemId = i.Id) As hal
WHERE i.Id = 2
这有什么问题吗?
I need to write a query of the scenario but I am lost writing it.
Assume there are two tables Items and Bids. The items are being selected via some sort of filter
SELECT i.* FROM Items i WHERE i.Id = 2
Now there is a Bids table having "ItemId" column to link Items to Bids. Now I want all items' data with HighestBid, LowestBid and TotalBids and I am trying this but it's not working.
SELECT i.*, hal.*
FROM Items i, (SELECT MAX(b.OfferAmount), MIN(b.OfferAmount), COUNT(b.*) FROM Bids b WHERE b.ItemId = i.Id) As hal
WHERE i.Id = 2
Is there something wrong with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
Try this