从当前周获取记录

时间:2013-11-13 10:03:05

标签: mysql

只需要获取当前周的记录。创建的列格式为“2013-11-13 00:00:00

SELECT COUNT( * ) AS con 
FROM  `accounts` 
WHERE  `description` LIKE  '%Earned%'   AND created = __________

2 个答案:

答案 0 :(得分:3)

使用YEARWEEK()

SELECT COUNT( * ) AS con 
FROM  `accounts` 
WHERE  `description` LIKE  '%Earned%'   
AND yearweek(created) = yearweek(curdate())

SQLFiddle demo

答案 1 :(得分:1)

SELECT COUNT( * ) AS con 
FROM  `accounts` 
WHERE  `description` LIKE  '%Earned%'   AND
WEEK(created) = WEEK(curdate()) AND 
YEAR(created) = YEAR(curdate())