2017-08-23 10 views
0

Tabellen und Spalten sind BelowWie mache ich diese Select-Anweisung?

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) 

ich das Fahrrad mit den meisten Gesamtbestand verfügbar d Lager von Marke + Lager von Bike Shop auswählen möchten? Wie mache ich das? Das habe ich bisher und es wird nicht ausgeführt.

Select model, price, rating, state, brands.brandname, brands.website, 
bikebrandsellstock.size, bikebrandsellstock.brandstock, bikeshopsellbike.bikeshopname, bikeshopsellbike.size, bikeshopsellbike.bikeshopstock 
from bikes 
INNER JOIN brands ON bikes.model = brands.model 
INNER JOIN bikebrandsellstock ON bikes.model = bikebrandsellstock.model 
INNER JOIN bikeshopsellbike ON bikes.model = bikeshopsellbike.model 
WHERE SUM(bikebrandsellstock.stock+bikeshopsellbike.stock) 
IN (SELECT MAX(SUM(bikebrandsellstock.stock+bikeshopsellbike.stock))) 
+1

Omer, Ihre Bearbeitung war eine Regression und es wurde rückgängig gemacht. Sie haben die Abfrageformatierung, die coldspeed in –

Antwort

0

Vielleicht sind Sie es Grübeln:

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 
0

Ihre Syntax in (SELECT MAX(SUM(bikebrandsellstock.stock+bikeshopsellbike.stock))) falsch ist, können Sie eine FROM Anweisung fehlen.

+0

setzte, zerstört. Es scheint, dass JC erwartet, dass die Unterabfrage funktioniert, da sie Tabellenaliase aus der übergeordneten Abfrage verwendet. Ihre Antwort könnte von einer Erklärung profitieren, warum dies in diesem Kontext nicht funktioniert? –

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; 

Diese Lösung berücksichtigt keine Bindungen.

Verwandte Themen