表和列位于
之下VSTest C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow
我想选择总库存最多的自行车,即自行车店的品牌+库存?我该怎么做呢?这是我到目前为止所没有执行的。
Bikers(BikerName, Country, Age, Category, World_Cup_Wins,
World_Championship_Wins, Brand, Bike)
BikerMeetUp(BikerName, Date, Location)
BikeShopInfo(BikeShopName, Telephone_Number, Address, Website)
Brands(BrandName, Website, Model)
Bikes(Model, Price, Weight, Colour, Rating, State)
BikeTyre(Model, Tyre_Model, Size)
BikeForks(Model, Fork_Model, Travel)
BikeBrandSellStock(Model, Size, BrandStock)
BikeShopSellBike(BikeShopName, Model, Size, BikeShopStock)
答案 0 :(得分:0)
也许你过度思考它:
SELECT *
FROM
bikebrandsellstock b
INNER JOIN
bikeshopsellbike s
ON s.model = b.model and s.size = s.size
ORDER BY b.brandstock + s.bikeshopstock DESC
LIMIT 1
答案 1 :(得分:0)
(SELECT MAX(SUM(bikebrandsellstock.stock+bikeshopsellbike.stock)))
中的语法不正确,您错过了FROM
语句。
答案 2 :(得分:0)
SELECT model
, SUM(stock) total
FROM
( SELECT Model, BrandStock stock FROM BikeBrandSellStock
UNION
SELECT Model, BikeShopStock FROM BikeShopSellBike
) x
GROUP
BY model
ORDER
BY total DESC
LIMIT 1;
此解决方案不考虑关系。