我想每年都不算身份证。 我的表号:- id号,s_date日期 和数据
\x{e76f}\x{e76f}( s_date )
+
2013年-10-15 x
2013年- 10 -27 x
2013年-10-27 x
2013年-10-27 x
2013-01-27 x
2013年-11-11 x
2013年-11-10
2012年-11-10 x
2013年-01-10
2012年-10-27 x
2013年-10-16 x
2013年-10-16 x
2013年-10-16 x
2013年-10-17 x
2013年-10-17 x
2013年-10-17 x
2013年-10-18 x
2013年-10-26 x
我想做点什么
+
tot _ year1 _x
+
2/ 2012
[ 16 ]2013年
+
我的商店手续是:-
mysql>创建过程sen49()
-> begin
-> declare year1 datetime;
-> declare tot INT;
-> select count(id) INTO tot,year(s_date) INTO year1 from year_info group by year(s_date);
-> end $$
错误:-
错误1327 (42000):未声明的变量:年份
所以请帮我解决这个错误..。年声明我尝试日期和varchar数据type...but没有解决此错误。
发布于 2013-11-20 14:04:18
试试这个密码-
BEGIN
SELECT YEAR(s_date) year, COUNT(*) count FROM year_info GROUP BY YEAR(s_date);
END
发布于 2013-11-20 13:59:33
简单:
SELECT COUNT(*), SUBSTRING(s_date, 1, 4) AS Year
FROM table
GROUP BY SUBSTRING(s_date, 1, 4)
如果需要,MySQL可以将日期字段视为“字符串”,并以ISO格式存储它们(YYYY)。
https://stackoverflow.com/questions/20097903
复制相似问题