2016-12-01 119 views
-1

图片: More information about the structure of the tables "offer" and "bid". Also a "Expected result" wich is shown the result. <-- really Important我怎样才能显示所有“文章”至少有3个“出价”?

我想表明的是有3个以上“投标”所有的“报价”的“ArticleName的”。应该输出“投标”的数量。 我不知道如何写下来。但我想我知道逻辑。它应该统计表格“出价”和列“OID”的相同数量,最后它应该粘贴大于3的数字。我想真正学习SQL,你知道一个页面很容易理解?

我希望你能帮助我。

问候 绿茶

回答

0
SELECT * FROM (
    SELECT o.ArticleName, count(b.BID) as numberOfBids 
    FROM Offer as o INNER JOIN bid as b ON o.oid = b.oid 
    GROUP BY o.ArticleName 
) as c 
WHERE c.numberOfBids > 3 
0

嗯,这是很容易:

Select ArticleName 
    , count(*) NumberOfBids 
    from Offer o 
    join Bid b 
    on b.oid = o.oid 
group by ARticleName 
having count(*) >= 3 
相关问题