mysql常用语句
-- 取余
SELECT
7 MOD 3;
-- 取整
SELECT
7 DIV 3;
-- 判断日期是周几
SELECT
DAYOFWEEK( '2021-09-01 21:28:00' );
-- 判断今天周几(优化版)
SELECT
CASE
dayofweek( now( ) )
WHEN 1 THEN
'星期日'
WHEN 2 THEN
'星期一'
WHEN 3 THEN
'星期二'
WHEN 4 THEN
'星期三'
WHEN 5 THEN
'星期四'
WHEN 6 THEN
'星期五'
WHEN 7 THEN
'星期六'
END
FROM
DUAL;
-- 一年周的天数
SELECT WEEK
( '2021-01-14' );
-- 计算2个日期之间的工作日天数(排除周6周日)
SELECT
5 * ( DATEDIFF( '2021-09-03', '2021-09-02' ) DIV 7 ) + MID( '0123444401233334012222340111123400012345001234550', 7 * WEEKDAY( '2021-09-02' ) + WEEKDAY( '2021-09-03' ) + 1, 1 )
|