Select SUM(Breakfast) FROM `expense` WHERE MONTHNAME(Date)='February'
Select (BreakFast+lunch+dinner) as Total FROM `expense` WHERE Date='2016-01-01'
合併結果取決於條件。查詢合併兩個結果取決於條件
SUM(Breakfast)
如果是2月份,應該選擇。
如果不是意味着
(BreakFast+lunch+dinner) as Total
必須加油特定日期。
我嘗試了聯盟,但我沒有得到期望的結果
Table expense
--------------
Date Breakfast Lunch Dinner
2016-02-02 20 20 30
2016-02-03 30 30 20
2016-01-02 40 30 20 90(If It is a month Of Not a Feb)
50(If It is a month Of Feb)
--------------------------
的MySQL或SQL Server?你已經標記了他們兩個。 – Fred
不知道問題是什麼。 – shawnt00