我有一個這樣的表。現在我想要兩個總和(小時).. 1爲place_type'1',另一個爲place_type'2'。在MySQL中可能嗎?現在在mysql中使用值的總和
我的查詢是
SELECT sum(hour) as totalHour from category_data group by category_data.user_id
也試圖與IF條件,但不是事先工作
SELECT IF(place_type='1',sum(hour),0) home,
IF(place_type='2', sum(hour), 0) center,
from category_data group by category_data.user_id
user_id place_type hour
1 1 2
1 2 5
2 1 3
2 2 4
3 1 2
感謝
我有這樣 – Strawberry