我在这里苦苦挣扎
我有两张桌子:
item(IID, description, category, price)
buys(UID,IID,Price)
查询是查找大多数用户购买的商品。 我试过这个:
SELECT Distinct Description, Count(buys.UID) AS TimesBought From item,buys
Where item.IId=buys.IID
Group by Description Order by TimesBought;
返回所有类别以及此类别中的商品购买次数。
请帮忙
答案 0 :(得分:2)
SELECT item.IID, Count(item.IID) AS TimesBought
From item inner join buys
on item.IId = buys.IID
Group by item.IId Order by TimesBought