SELECT shop.price,shop.item,shop.full_item_name,shop.qty,shop.shop_id,
SUM(averages_20128.combined_prices + averages_20127.combined_prices) AS combined,
SUM(averages_20128.total_sales + averages_20127.total_sales) AS total
FROM `shop`
JOIN `averages_20128`
ON averages_20128.full_item_name=shop.full_item_name
JOIN `averages_20127`
ON averages_20128.full_item_name=averages_20127.full_item_name
JOIN `theShops`
ON theShops.id=shop.shop_id
WHERE shop.price<combined/total
AND theShops.open='1'
AND shop.id!=''
AND `total`>10
ORDER BY combined/total DESC
LIMIT 100
錯誤:在未知列'合併「where子句」結合SUM和WHERE - 沒有得到我期望的結果
概述:我已經考慮創建存儲當前平均列和排序上但是,我剛開始時並沒有這樣做,現在已經有了數據。我寧願不經過這一切並重新計算這一點。所以我希望MySQL能爲我做數學。
當我遺漏了WHERE/ORDER子句時,這會起作用,導致我相信我的語法有問題。
你先生,是個紳士和學者,今天想到了我很多!謝謝! – 2012-02-22 19:44:43
我將闡明我將ORDER BY更改爲:ORDER BY shop.price-(combined/total)ASC ...因此,基本上它試圖將商品銷售低於平均水平的商店,然後再訂購最高的節省。 – 2012-02-22 20:07:23