2
我需要執行下面的查詢:SQL原料到MySQL查詢
select Clients.Zip, AVG(SpentT) as Average_Spent_Per_Zipcode
from
(select CLIENT.CLIENT_ID AS ClientID, Averages.Spent AS SpentT, CLIENT.ZIPCODE AS Zip
from CLIENT,
(select CLIENT_ID, AVG(MENU.PRICE) AS Spent
from ORDER_HISTORY, MENU
where (ORDER_HISTORY.FOOD = MENU.FOOD)
AND (ORDER_HISTORY.RESTAURANT_ID = MENU.RESTAURANT_ID)
group by ORDER_HISTORY.CLIENT_ID)
AS Averages
where CLIENT.CLIENT_ID = Averages.CLIENT_ID) AS Clients
group by Clients.Zip
order by Average_Spent_Per_Zipcode DESC
我知道這可能不是最簡單的查詢,但這個想法是找到在餐廳上花費最多的郵編平均。
我已經試過
sqlP1=text('select Clients.Zip, AVG(SpentT) as Average_Spent_Per_Zipcode from (select CLIENT.CLIENT_ID AS ClientID, Averages.Spent AS SpentT, CLIENT.ZIPCODE AS Zip from CLIENT, (select CLIENT_ID, AVG(MENU.PRICE) AS Spent from ORDER_HISTORY, MENU where (ORDER_HISTORY.FOOD = MENU.FOOD) AND (ORDER_HISTORY.RESTAURANT_ID = MENU.RESTAURANT_ID) group by ORDER_HISTORY.CLIENT_ID) AS Averages where CLIENT.CLIENT_ID = Averages.CLIENT_ID) AS Clients group by Clients.Zip order by Average_Spent_Per_Zipcode DESC')
result= db.engine.execute(sql)
,但我不斷收到任何錯誤,我是新來這個,所以我不知道如果日誌將有助於/其中id找到他們。
如果有人知道如何執行這個查詢,那就太棒了! 您的幫助非常感謝!
你能後請 – Adrian 2014-12-05 02:27:19
內部服務器錯誤 服務器遇到一個內部錯誤,無法完成您的請求的錯誤。服務器過載或應用程序出現錯誤。 @Adrian我不知道如何檢查日誌以獲得更精確的錯誤。有可能是我缺少一些進口嗎? – Brandon 2014-12-05 04:19:55