SQL按每日查询

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/z040145/article/details/50543465
查询一段时间内,每天有多少注册量:
select count(*) as count,RegDate from user where RegDate between "2014-01-01" and "2014-04-04" group by day(RegDate) order by RegDate;

查询结果
3          2014-01-13 16:52:19
1          2014-03-03 15:00:41
1          2014-03-10 15:35:18
1          2014-03-20 17:00:05
1          2014-03-25 14:37:11
2          2014-03-26 17:42:15


//根据要求的日期来取数据
    var sqlPeriod;
    if(period == "day"){
        sqlPeriod="day(RegDate),month(RegDate),year(RegDate)";
    }else if(period == "month"){
        sqlPeriod="month(RegDate),year(RegDate)";
    }else if(period == "year"){
        sqlPeriod="year(RegDate)";
    }else if(period == "week"){
        sqlPeriod="week(RegDate)";
    }else if(period == "quarter"){
        sqlPeriod="quarter(RegDate)";
    }

“select count(*) as count,RegDate as regDate from user where RegDate between ? and ? group by "+sqlPeriod+" order by RegDate",[startDate,endDate]
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页