关于查询当月数据的问题
数据库有表tbBiao,字段(riqi)是日期2012-04-15这样,姓名(name)小明,每上班一次就会有一条记录,我想实现:查询小明当月总共上班次数。
我是这样的语句:SELECT COUNT(*) AS riqi
FROM tbBiao
WHERE (name = '小明') AND
((SELECT SUBSTRING(riqi, 7, 1) AS riqi
FROM tbBiao AS tbBiao_1
WHERE (name = '小明')) = '4')
___________________________
这样会报错:[子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。]
请高手指教!!
------解决方案--------------------
SELECT COUNT(*) AS riqi
FROM tbBiao
WHERE (name = '小明') AND
SUBSTRING(riqi, 7, 1)='4'
这样就行了,日期这不用再select了