我試圖從不同的表中添加總值的總和。這是查詢成功但我想添加當前日期。添加兩個表值與當前日期(今天的日期)
表1 表2
日期 TOTAL_COST日期 TOTAL_COST
21/01/2015 21/01/2015
SELECT (SELECT SUM(Total_Cost) FROM Table1) + (SELECT SUM(Total_Cost) FROM Table2) as total
它給予適當的答案:1000
但我運行此查詢添加具有當前日期。
SELECT (SELECT SUM(Total_Cost) FROM Table1 WHERE DATE = CURDATE()) + (SELECT SUM(Total_Cost) FROM Table2 WHERE DATE = CURDATE()) as total
其給定值:NULL
請幫我有人來解決這個預先感謝您。
當你運行這個查詢時你會得到什麼? SELECT Total_Cost FROM Table1 WHERE DATE = CURDATE() or this SELECT Total_Cost FROM Table2 WHERE DATE = CURDATE() – 2015-01-21 09:24:54
您在table2中的日期的年份爲'2105'而非'2015'! – 2015-01-21 09:26:22
它給今天的日期Total_Cost所有的價值,但我想兩個表Total_Cost和它與當前日期的加法總和 – 2015-01-21 09:29:23