《mysql必知必会》学习_第11章_20180801_欢
第11章:使用數據處理函數。
P69 文本處理函數,upper()函數把文本變成大寫字體。
select vend_name,upper(vend_name) as vend_name_upcase from vendors order by vend_name; #upper()把vend_name列的文本變成了大寫,并且重新命名為vend_name_upcase #
其他的常用的函數:
length()返回串的長度
lower() 將文本變成小寫字體。
其他的,left()返回串左邊的字符,locate()找到串的一個子串。 LTrim()去掉串左邊的空格,Right()返回串右邊的字符。substring()返回子串的字符。試了一下,不知道怎么用,或是不知道用不用有什么區別。
select cust_name,cust_contact from customers where cust_contact ='Y.Lie';? #查找列cust_contact里面名Y.Lie,但是沒有沒有這個顧客名,所以返回的值是空的#
select cust_name,cust_contact from customers where soundex(cust_contact)=soundex('Y.Lie); #soundex()函數搜索發音類似的,類似模糊搜索,注意條件的里邊都要用soundex()函數。#
P71 日期和時間處理函數。注意:為了排除多義性混亂的各種可能性,日期的首選首選格式:yyyy-mm-dd。
select cust_id,order_num from orders where order_date='2005-09-01';? #檢索訂單日期是2005-09-01 #
select cust_id,order_num from orders where date(order_date)='2005-09-01';? #倘若訂單日期的格式是yyyy-mm-dd xx:xx:xx? ,那where order_date='2005-09-01'就會檢索失敗,為了保險起見,用date()函數,提取日期的部分信息,相應地,如果想要時間的時間時部分(即是xx:xx:xx部分),用time()函數,如:where time(order_date)=13:08:22 #
?
?P73 檢索一段時間內的信息。
select cust_id,order_num from orders where date(order_date) between '2005-09-01' and '2005-09-30'; #檢索的時間范圍是20050901到20050930#
select cust_id,order_num from orders where year(order_date)=2005 and month(order_date)=9 ; #檢索的年份是2005,月份是9月,要同時滿足這兩個條件。#注意:上面檢索的是時間格式,所以要用引號,下面檢索的年份和月份已經相當于一個數值,不需要引號(自己的理解)#
其他的數值處理函數有:
abs() 絕對值;
cos()一個角度的余弦
exp()一個值的指數值
mod()返回除操作的余數? #不懂它的操作#
pi()返回圓周率
rand()返回一個隨機值
sin()返回一個角度的正弦
sqrt()返回一個數的平方根
tan()返回正切值
?
?
?
轉載于:https://www.cnblogs.com/qiyuanjiejie/p/9406349.html
總結
以上是生活随笔為你收集整理的《mysql必知必会》学习_第11章_20180801_欢的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 基础 | 命名和运算
- 下一篇: Jmeter连接到Mysql