你好
我有如下的MySQL表列:COND 額定值1,rating2,價格,覈定MYSQL不同條件
是否有可能選擇的結果是這樣的:
select
average rating1 + rating2 as total_rating,
average rating1 as rating1,
average rating2 as rating2,
average price if cond = '1' as price_used
average price if cond = '2' as price_new
where approved = '1'
到目前爲止,我有:
SELECT
(AVG(t.rating1) + AVG(t.rating2))/2 AS total_rating
AVG(t.rating1) AS rating1,
AVG(t.rating2) AS rating2,
---- price statements?? ----
FROM t
WHERE 1=1
AND t.approved = '1'
非常感謝,並原諒我的英語
不,它不工作,很遺憾。 price_used返回一個值,但絕對不是平均值,price_new返回0 – 2011-01-07 22:24:03
您收到任何錯誤? – Chandu 2011-01-07 22:28:37
沒有錯誤,但在price_new上出現空的結果,在price_used上出現錯誤的平均值 – 2011-01-07 22:30:08