2017-11-11 168 views
0

我會解釋我迄今爲止所做的事情,並在最後問我的問題。SQL Server - 從表中選擇一個特定的ID

首先,我建立了我的外部&內部變量(注意@EDelivery是包含在列FoodIDQuantity表類型):

@EDelivery DeliveryTblType readonly 
Declare @NumberOfMinutes smallint, @FoodWeight int, @WeightCapacity int, 
@DroneID int, @TimeOfWeek varchar 

然後我讀這,給我的所有項目的總重量訂購併在承重能力宣讀了DronesTbl

select @FoodWeight = SUM(FoodWeight * Quantity) 
from @EDelivery as del 
inner join Foods on del.FoodID = Foods.FoodID 

select @WeightCapacity = Drones.WeightCapacity 
from dbo.Drones 

我的問題是我該如何選擇具體的無人機比較其weightcapacity到TH e食品總重量

+0

您不使用MySQL,MySQL不支持GETDATE和throw等函數。我已將MySQL標記更改爲SQL服務器標記 –

+0

感謝您告知我 –

回答

0

您需要根據@droneid值設置變量@WeightCapacity。現在,你將這個變量設置爲無人機表中的最後一個無人機。

如果你改變你的第二個查詢到下面的內容那麼它應該工作。

select @WeightCapacity = 
    Drones.WeightCapacity 
     from dbo.Drones 
     where DroneID [email protected] 
+0

我不知道爲什麼我沒有看到這個,感謝您的幫助 –

+0

當然,不客氣。 – Sunil

相關問題