请赐教按月份查询记录的SQL语句,我用的是MYSQL,谢谢!
以下这条语句我如何把它改成,只显示当月的查询记录:
sql = "select sum(khJinE) as sQdje from khxx where uId= ' "+uId+ " ' ";
khxx表中有日期字段: "jrrq " 格式是: “2007-3-23”
如果我想一年中12个月的记录,分别显示该怎么写?
如:
<a herf= "xx.asp?m=1 "> 一月 </a>
<a herf= "xx.asp?m=1 "> 二月 </a>
......
谢谢!
------解决方案--------------------1月份: "select sum(khJinE) as sQdje from khxx where uId= ' "+uId+ " ' and MONTH( ' "+jrrq+ " ')=1 ";
2月份: "select sum(khJinE) as sQdje from khxx where uId= ' "+uId+ " ' and MONTH( ' "+jrrq+ " ')=2 ";
下面以此类推。。。。。。。。。。。。。。。。
------解决方案--------------------select sum(khJinE),MONTH(jrrq) from khxx group by MONTH(jrrq);