
本季度的第一天 ,然后你可以把字符串再转换为日期。 方法很多,包括同一个函数的别名(同义词)也很多。比如CURDATE(),CURRENT_DATE(), CURRENT_DATE, NOW 等都可以返回当天
mysql教程> select CURDATE(),ELT(QUARTER(CURDATE()),
-> year(CURDATE())1000+0101,
-> year(CURDATE())1000+0401,
-> year(CURDATE())1000+0701,
-> year(CURDATE())1000+1001) as firstDayofQ;
+------------+-------------+
| CURDATE() | firstDayofQ |
+------------+-------------+
| 2009-05-19 | 2009401 |
+------------+-------------+
1 row in set (000 sec)
mysql>
用mysql语句获取本季度的第一天
本月的第一天,
date(
concat(year(curdate()),'-',month(curdate()),'-','1'))
本周的第一天
curdate()-
WEEKDAY(curdate())
用mysql语句获取本季度的第一天
一、打开MySQL工具,我用的是Navicat Premium
二、新建查询,输入sql命令
举例如下:
分组查询
1、年度分组
2、月度分组
3、先按年度分组,再按月度分组
4、按年月分组
SELECT count(ArticleId), date_format(FROM_UNIXTIME( `BlogCreateTime`),'%y%m') sdate FROM `blog_article` group by sdate
结果:
count( ArticleId ) sdate
17 0901
11 0902
5 0903
6 0904
2 0905
1 0907
12 0908
6 0909
11 0910
3 0911
其他方法参考:
我想做一个统计,数据库是mysql,统计出每天,每周,每月的记录数
建表的时候加个字段表示日期,然后查sql手册
select count() from `table` where `date`='{某天}'
select count() from `table` where date_format(`date`,'%V')='{某周}'
select count() from `table` where date_format(`date`,'%c')='{某月}'
另一种方法:
select count( ) from projects where editdate >= '2007-11-9 00:00:00' and editdate <=
'2007-11-9 24:00:00';
第三种方法:
每周的
SQL codeselect count() as cnt,week(editdate) as weekflg from projects where year(editdate)
=2007 group by weekflg
每月
SQL codeselect count() as cnt,month(editdate) as monthflg from projects where year
(editdate)=2007 group by monthflg
每天
SQL codeselect count() as cnt from projects group by date(editdate)
mysql中DATE_FORMAT(date, format)函数可根据format字符串格式化日期或日期和时间值date,返回结果
串。
也可用DATE_FORMAT( ) 来格式化DATE 或DATETIME 值,以便得到所希望的格式。根据format字符串格式
化date值:
下面是函数的参数说明:
%i 两位数字形式的分( 00,01, , 59)
%H 两位数字形式的小时,24 小时(00,01, , 23)
%h, %I 两位数字形式的小时,12 小时(01,02, , 12)
%k 数字形式的小时,24 小时(0,1, , 23)
%l 数字形式的小时,12 小时(1, 2, , 12)
%T 24 小时的时间形式(hh : mm : s s)
%r 12 小时的时间形式(hh:mm:ss AM 或hh:mm:ss PM)
%p AM 或P M
%W 一周中每一天的名称( Sunday, Monday, , Saturday)
%a 一周中每一天名称的缩写( Sun, Mon, , Sat)
%d 两位数字表示月中的天数( 00, 01, , 31)
%e 数字形式表示月中的天数( 1, 2, , 31)
%D 英文后缀表示月中的天数( 1st, 2nd, 3rd, )
%w 以数字形式表示周中的天数( 0 = Sunday, 1=Monday, , 6=Saturday)
%j 以三位数字表示年中的天数( 001, 002, , 366)
% U 周(0, 1, 52),其中Sunday 为周中的第一天
%u 周(0, 1, 52),其中Monday 为周中的第一天
%M 月名(January, February, , December)
%b 缩写的月名( January, February, , December)
%m 两位数字表示的月份( 01, 02, , 12)
%c 数字表示的月份( 1, 2, , 12)
%Y 四位数字表示的年份
%y 两位数字表示的年份
%% 直接值“%”
以上就是关于如何 用mysql语句获取本季度的第一天 本月全部的内容,包括:如何 用mysql语句获取本季度的第一天 本月、mysql 自动分月统计、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)