sqlite查询来查找给定date的一年的总和

我写了一个查询: SELECT YEAR(Date),SUM(replace(price, ',', '')) FROM example GROUP BY year(date); 。我试图得到那一年的所有价格的总和,但我得到一个错误 – 没有这样的function:一年。 请指导我,我是db的noob。再次感谢。

 12/10/11 377,245.67 12/19/11 5,104,245.00 12/28/11 23,332.98 12/24/10 126,875.21 12/24/10 5,112,225.14 12/23/10 4,552.54 11/24/10 402.82 10/15/09 132,875.32 9/19/09 126,334,123.32 9/23/09 345,887.21 9/29/09 16,520.11 9/28/09 388,902.02 11/12/08 24,622.43 10/25/08 278,916.52 10/12/08 42.22 9/22/08 17,234.01 9/16/08 377,245.67 12/15/07 5,104,245.00 12/18/07 23,332.98 12/19/07 126,875.21 12/22/07 23,332.98 12/28/07 126,875.21 

格式我正在寻找:

 Year(Date) price 8 438483479.3 9 8774343479 10 5654389.34 11 5654354646 12 23434483479 

尝试这个

 SELECT strftime('%Y', Date),SUM(replace(price, ',', '')) FROM example GROUP BY strftime('%Y', Date); 

我build议这个sintax:

 SELECT strftime('%Y',Date), SUM(replace(price, ',', '')) FROM example GROUP BY strftime('%Y',Date); 

希望能帮助到你

在sqlite中没有函数year() 。 你必须使用函数strftime()来代替。

例如,要获取字段Date的年份值,可以使用strftime("%Y", Date)

因此,您必须通过strftime("%Y", Date)在查询中replaceyear(Date) strftime("%Y", Date)