2019-03-12

1、整理今天所學(xué)的知識點

、、、、、、、、、、、、、、、、、、、、、、、、、、

2、內(nèi)置函數(shù)

1、字符串

1、length

select LENGTH("abc中國");

select ename,LENGTH(ename) from EMP;

2、concat

select CONCAT("a","bc","xx");

3、str_to_date

select STR_TO_DATE("2018年02月03日","%Y年%m月%d日");

create table tt(

id int auto_increment primary key,

birthday date

);

insert into tt(birthday) values("2018-2-4");

insert into tt(birthday) values(STR_TO_DATE("2018年02月03日","%Y年%m月%d日"));

select * from tt;

2、數(shù)字

1、floor,ceil

select FLOOR(1.56),CEIL(1.16);

2、rand

select RAND(10);

3、日期

1、now

select NOW();

select DAYOFWEEK('2018-08-26');

2、date_format? 日期轉(zhuǎn)字符串

select DATE_FORMAT(NOW(),"%Y年%m月%d日 %H時%i分%s秒");

select DATE_FORMAT("2018-2-3","%Y年%m月%d日");

2、視圖

創(chuàng)建視圖

create view myview

as

select avg(sal) avg_sal,deptno from EMP group by deptno;

使用視圖

select * from myview;

3、事務(wù)

下訂單:

1、insert訂單表

2、update商品表

3、insert物流表

.......

轉(zhuǎn)賬:

1、update轉(zhuǎn)出

2、update轉(zhuǎn)入

3、insert交易記錄

.......

事務(wù):

事務(wù)開始

增刪改語句

事務(wù)提交/回滾

目的:讓多個操作同生共死,保證數(shù)據(jù)的正確性。

drop table bank;

create table bank(

id int primary key,

money int

);

insert into bank values(1,10);

insert into bank values(2,1);

select * from bank;

begin;

update bank

set money = money-5

where id = 1;

update bank

set money = money+5

where id = 2;

rollback;

commit;

select * from bank;

begin;

savepoint p1;

update bank

set money = money-1

where id = 1;

savepoint p2;

update bank

set money = money-1

where id = 1;

savepoint p3;

update bank

set money = money-1

where id = 1;

savepoint p4;

rollback to p4;

commit;

4、賬戶管理

1、root登陸

mysql -uroot -p

2、選擇數(shù)據(jù)庫

use mydb

3、創(chuàng)建用戶并授權(quán)

grant select,insert on mydb.* to 'laowang'@'%' identified by '123456'

4、修改權(quán)限

grant 權(quán)限名稱 on 數(shù)據(jù)庫 to 賬戶@主機 with grant option;

5、修改密碼

update user set authentication_string=password('新密碼') where user='用戶名';

6、登陸測試

mysql -ulaowang -p

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

2、sql函數(shù),整理30個。

、、、、、、、、、、字符串函數(shù)、、、、、、、、、、、、、、

1.[if !supportLists]·? ? ? 查看字符的ascii碼值ascii(str),str是空串時返回0

select ascii('a');

2.[if !supportLists]·? ? ? ? 查看ascii碼值對應(yīng)的字符char(數(shù)字)

select char(97);

3.[if !supportLists]·? ? ? ? 拼接字符串concat(str1,str2...)

select concat(12,34,'ab');

4.[if !supportLists]·? ? ? ?包含字符個數(shù)length(str)

select length('abc');

5.left(str,len)返回字符串str的左端len個字符

6.right(str,len)返回字符串str的右端len個字符

7.substring(str,pos,len)返回字符串str的位置pos起len個字符

select substring('abc123',2,3);

8.ltrim(str)返回刪除了左空格的字符串str

9.rtrim(str)返回刪除了右空格的字符串str

10.trim([方向 remstr from str)返回從某側(cè)刪除remstr后的字符串str,方向詞包括both、leading、trailing,表示兩側(cè)、左、右

select trim('? bar?? ');

select trim(leading 'x' FROM 'xxxbarxxx');

select trim(both 'x' FROM 'xxxbarxxx');

select trim(trailing 'x' FROM 'xxxbarxxx');

返回由n個空格字符組成的一個字符串space(n)

select space(10);

11.替換字符串replace(str,from_str,to_str)

select replace('abc123','123','def');

12. lower(str)大寫轉(zhuǎn)小寫

13. upper(str)小寫轉(zhuǎn)大寫

select lower('aBcD');

????????????????????????????????????????????????數(shù)學(xué)函數(shù)

14 求絕對值abs(n)

select abs(-32);

15. 求m除以n的余數(shù)mod(m,n),同運算符%

select mod(10,3);

select 10%3;

16.地板floor(n),表示不大于n的最大整數(shù)

select floor(2.3);

17.天花板ceiling(n),表示不小于n的最大整數(shù)

select ceiling(2.3);

18. 求四舍五入值round(n,d),n表示原數(shù),d表示小數(shù)位置,默認為0

select round(1.6);

19.求x的y次冪pow(x,y)

select pow(2,3);

20. 獲取圓周率PI()

select PI();

21. 隨機數(shù)rand(),值為0-1.0的浮點數(shù)

select rand();

、、、、、、、、、日期函數(shù)、、、、、、、、、、、

22.? year(date)返回date的年份(范圍在1000到9999)

23.? month(date)返回date中的月份數(shù)值

24.? day(date)返回date中的日期數(shù)值

25.? hour(time)返回time的小時數(shù)(范圍是0到23)

26.? minute(time)返回time的分鐘數(shù)(范圍是0到59)

27.? second(time)返回time的秒數(shù)(范圍是0到59)

28.? 日期格式化date_format(date,format),format參數(shù)可用的值如下

? 獲取年%Y,返回4位的整數(shù)

* 獲取年%y,返回2位的整數(shù)

* 獲取月%m,值為1-12的整數(shù)

29.? 獲取日%d,返回整數(shù)

* 獲取時%H,值為0-23的整數(shù)

* 獲取時%h,值為1-12的整數(shù)

* 獲取分%i,值為0-59的整數(shù)

獲取秒%s,值為0-59的整數(shù)

/*日期-->字符串*/

select date_format('2017-10-20','%Y年%m月%d日')

/*字符串-->日期*/

select str_to_date('2017年10月20日','%Y年%m月%d日')

30.? 當(dāng)前日期current_date()

select current_date();

? 當(dāng)前時間current_time()

select current_time();

? 當(dāng)前日期時間now()

select now();


、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

3、實現(xiàn)sql字符串轉(zhuǎn)日期,日期轉(zhuǎn)字符串



、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、


4、實現(xiàn)python字符串轉(zhuǎn)日期,日期轉(zhuǎn)字符串



、

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

5、安裝pymysql,使用python代碼實現(xiàn)增刪改查。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容