mysql 如何获取每周的第一天
发布网友
发布时间:2022-04-22 01:06
我来回答
共2个回答
懂视网
时间:2022-05-02 11:34
#当年最后一天:
SELECT concat(YEAR(now()),‘-12-31‘);
#当前week的第一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 1 DAY);
#当前week的最后一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) - 5 DAY);
#前一week的第一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 8 DAY);
#前一week的最后一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 2 DAY);
#前两week的第一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 15 DAY);
#前两week的最后一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 9 DAY);
#当前month的第一天:
SELECT concat(date_format(LAST_DAY(now()),‘%Y-%m-‘),‘01‘);
#当前month的最后一天:
SELECT LAST_DAY(now());
#前一month的第一天:
SELECT concat(date_format(LAST_DAY(now() - interval 1 month),‘%Y-%m-‘),‘01‘);
#前一month的最后一天:
SELECT LAST_DAY(now() - interval 1 month);
#前两month的第一天:
SELECT concat(date_format(LAST_DAY(now() - interval 2 month),‘%Y-%m-‘),‘01‘);
#前两month的最后一天:
SELECT LAST_DAY(now() - interval 2 month);
#当前quarter的第一天:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),‘%Y-%m-‘),‘01‘);
#当前quarter的最后一天:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month);
#前一quarter的第一天:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-6 month),‘%Y-%m-‘),‘01‘);
#前一quarter的最后一天:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-4 month);
#前两quarter的第一天:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-9 month),‘%Y-%m-‘),‘01‘);
#前两quarter的最后一天:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-7 month);
0919MYSQL中取当前周/月/季/年的第一天与最后一天
标签:concat csdn string extract 代码 form uart nbsp mys
热心网友
时间:2022-05-02 08:42
给你个例子,是我这几天在开发过程中正在用的
SELECT DATE_FORMAT(JL_RQ,'%Y-%m') sj,SUM(jl_spsl) sl FROM sp_xs_lsjl WHERE JL_SPM='1' AND JL_RQ BETWEEN '2017-01-01' AND '2017-12-12' GROUP BY sj ORDER BY sj;