计算特定月份的条目

时间:2016-05-23 14:56:31

标签: mysql database count

我想在一个月内计算数据库中表格中的条目。例如,1月份的总条目。我试过这个,但它没有成功。

 SELECT MONTH(date1 = '$2015-01-01$') COUNT (*) COUNT from restowlist 
    WHERE MONTH(date1='$2015-01-01$')

请帮忙。

4 个答案:

答案 0 :(得分:0)

SELECT 
    COUNT(*)
FROM
    restowlist
WHERE
    MONTH(yourDateColumn) = 1 AND YEAR(yourDateColumn) = 2015

答案 1 :(得分:0)

 select count(*) 
 from restowlist 
 where month(date1) = 1
 and year(date1) = 2015

答案 2 :(得分:0)

你能试试吗

SELECT COUNT(*)
FROM restowlist
WHERE DATEPART('year', datecolumn) = 2015
AND DATEPART('month', datecolumn) = 1

(道歉,因为我的语法来自SQL,而不是MySQL)

答案 3 :(得分:0)

 SELECT COUNT(*) FROM `restowlist` 
 WHERE `date1` BETWEEN cast('2016-01-01' as DATE) 
 AND cast('2016-01-31' as DATE);