MySQL根據日期查詢常用語句

2021-10-23 17:24:13 字數 930 閱讀 1530

--今天

select

*from 表名 where to_days(時間欄位名)

= to_days(

now())

;--昨天

select

*from 表名 where to_days(

now())

- to_days( 時間欄位名)

<=

1--本週

select

*from 表名 where yearweek( date_format( 時間欄位名,

'%y-%m-%d'))

= yearweek(

now())

;--本月

select

*from 表名 where date_format( 時間欄位名,

'%y%m'

)= date_format( curdate(),

'%y%m'

)--上乙個月

select

*from 表名 where period_diff(date_format(

now(),

'%y%m'

),date_format(時間欄位名,

'%y%m')=

1--本年

select

*from 表名 where

year

( 時間欄位名 )

=year

(now()

)--上一月

select

*from 表名 where period_diff( date_format(

now(),

'%y%m'

), date_format( 時間欄位名,

'%y%m'))

=1

mysql常用語句 MySQL常用語句

create table student id int primary key auto increment comment 學號 name varchar 200 comment 姓名 age int comment 年齡 comment 學生資訊 修改表注釋 alter table studen...

三 MYSQL常用語句 查詢語句

複習第三天 2021 03 12 12 54 48 序號 函式 方法 含義 例子 備註 1show databases 顯示所有的資料庫 2use 資料庫名字 選擇某個資料庫 選擇zuoye資料庫 use zuoye 3create database 資料庫名字 建立資料庫 建立school資料庫 ...

php mysql 常用語句 mysql常用語句

一 修改mysql使用者密碼 mysql h localhost u root p 命令列登入 update user set password password 123456 where user root 二 資料庫操作 show databases 顯示資料庫 create database ...