mysql 函式例項 mysql常用函式示例

2021-10-18 10:04:11 字數 1670 閱讀 3698

create table `orders` (

`orderid` int(10) not null auto_increment comment '編號',

`productname` varchar(32) not null comment '名稱',

`orderdate` datetime not null comment '時間',

primary key (`orderid`)

) engine=innodb auto_increment=4 default charset=utf8;

/*data for the table `orders` */

insert into `orders`(`orderid`,`productname`,`orderdate`) values (1,'jarlsberg cheese','2008-11-11 13:23:44');

insert into `orders`(`orderid`,`productname`,`orderdate`) values (2,'***xyyyy','2008-01-12 15:03:14');

#1.4、date():提取日期或時間表示式的日期部分

select productname, date(orderdate) as orderdate from orders where orderid=1;

select productname, time(orderdate) as orderdate from orders where orderid=1;

#1.5、extract():返回日期(年月日)單獨部分

select extract(year from orderdate) as orderyear from orders where orderid=2;

select extract(month from orderdate) as ordermonth from orders where orderid=2;

select extract(day from orderdate) as orderday from orders where orderid=2;

#1.1、date_add():向日期新增指定的時間間隔

select orderid,date_add(orderdate,interval 1 day) as orderpaydate from orders;

#1.7、date_sub():從日期減去指定的時間間隔

select orderid,date_sub(orderdate,interval 1 day) as subtractdate from orders;

#1.8、datediff():返回兩個日期之間的天數

select datediff('2008-11-30','2008-11-20') as diffdate;

#1.9、date_format():用不同的格式顯示日期/時間

select date_format(now(),'%b %d %y %h:%i %p');

select version();##檢視當前mysql的版本

select database();##檢視當前資料庫是哪個

select now();##檢視當前系統時間

select curdate();##檢視當前日期

select curtime();##檢視當前系統時分秒

mysql常問內容 mysql常問問題

前言 一些自己遇到的問題及理解 需補充修改 索引型別 主鍵索引 普通索引 符合索引 唯一索引 全文索引 索引 查詢資料的資料結構,索引占用磁碟空間,更新資料的時候影響更新表的效率 資料儲存型別 聚簇索引 非聚簇索引 聚簇 採用b 樹的資料結構,聚簇索引葉子節點存放證章表的資料,所以主鍵索引就是用的聚...

mysql檢視mylog命令 mysql常用命令

連線mysql 1.登入mysql資料庫 mysql u使用者名稱 p密碼 示例 2.登入遠端主機的mysql mysql h遠端主機ip位址 u使用者名稱 p密碼 示例 注 建立使用者命令格式為 create user hehe 192.168.93.151 3.退出mysql命令 exit 修改...

mysql execute指令 mysql常用命令

一 游標 游標 cursor 是處理資料的一種方法,為了檢視或者處理結果集中的資料,游標提供了在結果集中一次一行或者多行前進或向後瀏覽資料的能力。可以把游標當作乙個指標,它可以指定結果中的任何位置,然後允許使用者對指定位置的資料進行處理。模版案例一 import if name main cnx c...