我想從日期和時間獲取總和(成本)的數據。我的表字段的數據類型是id是INT AUTO INCREMENT,dd是varchar,mm是varchar,yyyy varchar和dd值是01到31,mm值是01到12,年值是4位數年份(2016或2015 ... ) 正是我想要總和(成本)= 143從字符串中獲取數據字符串整型數據類型
SELECT SUM(cost) FROM costing
WHERE
((dd> CAST('05' AS SIGNED) AND mm= CAST('12' AS SIGNED) AND yyyy= CAST('2015' AS SIGNED))
AND
((dd<= CAST('23' AS SIGNED) AND mm = CAST('01' AS SIGNED) AND yyyy= CAST('2016' AS SIGNED)))
order by id
這看起來太過複雜。爲什麼不有'DATE'字段並做一個簡單的'BETWEEN'? –
這是癡呆。 – Strawberry