postgresql——數(shù)學函數(shù)介紹-創(chuàng)新互聯(lián)

1、數(shù)學函數(shù)

成都創(chuàng)新互聯(lián)自2013年起,先為永登等服務建站,永登等地企業(yè),進行企業(yè)商務咨詢服務。為永登企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。

  數(shù)學函數(shù)主要用來處理數(shù)值數(shù)據(jù),主要的數(shù)學函數(shù)有:絕對值函數(shù)、三角函數(shù)(包括正弦函數(shù)、正切函數(shù)、余切函數(shù)等)、對數(shù)函數(shù)、隨機數(shù)函數(shù)等。在有錯誤產(chǎn)生時,數(shù)學函數(shù)會返回空值null。

1.1、絕對值函數(shù)ABS(x)和返回圓周率的函數(shù)PI()

例子:求2,-3.3,-33的絕對值

testdb=# select abs(2),abs(-3.3),abs(-33);

 abs | abs | abs

-----+-----+-----

  2 | 3.3 | 33

(1 row)

例子:返回圓周率值,如下:

testdb=# select pi();

    pi

------------------

 3.14159265358979

(1 row)

1.2、平方根函數(shù)sqrt(x)和求余函數(shù)mod(x,y)

sqrt(x)返回非負數(shù)x的二次平方根

mod(x,y)返回x被y除后的余數(shù)。mod()對于帶有小數(shù)部分的數(shù)值也起作用,返回除法運算后的精確余數(shù)。

例子:求9和40的二次平方根:

testdb=# select sqrt(9),sqrt(40);

 sqrt |    sqrt

------+------------------

  3 | 6.32455532033676

(1 row)

注意:負數(shù)沒有平方根,如果所求值為負數(shù),將會提示錯誤信息。

例子:進行求余運算:

testdb=# select mod(31,8),mod(234,10),mod(45.5,6);

 mod | mod | mod

-----+-----+-----

  7 |  4 | 3.5

(1 row)

1.3、獲取整數(shù)的函數(shù)ceil(x),ceiling(x)和floor(x)

ceil(x)和ceiling(x)意義相同,返回不小于x的最小整數(shù)值,返回值轉(zhuǎn)化為一個bigint。

例子:使用ceil和ceiling函數(shù)返回最小整數(shù),如下:

testdb=# select ceil(-3.35),ceiling(3.35);

 ceil | ceiling

------+---------

  -3 |    4

(1 row)

例子:使用floor函數(shù)返回大整數(shù)值,如下

testdb=# select floor(-3.35),floor(3.35);

 floor | floor

-------+-------

  -4 |   3

(1 row)

1.4、四舍五入函數(shù)round(x)和round(x,y)

round(x)返回最接近于參數(shù)x的整數(shù),對x值進行四舍五入。

round(x,y)返回最接近于參數(shù)x的數(shù),其值保留到小數(shù)點后面y位,若y為負值,則將保留x值到小數(shù)點左邊y位。

例子:使用round(x)函數(shù)對操作數(shù)進行四舍五入,如:

testdb=# select round(-1.15),round(-1.68),round(1.15),round(1.68);

 round | round | round | round

-------+-------+-------+-------

  -1 |  -2 |   1 |   2

(1 row)

例子:使用round(x,y)函數(shù)對操作數(shù)進行四舍五入,如

testdb=# select round(1.38,1),round(1.38,0),round(231.36,-1),round(231.36,-2);

 round | round | round | round

-------+-------+-------+-------

  1.4 |   1 |  230 |  200

(1 row)

1.5、符號函數(shù)sign(x)

sign(x)返回參數(shù)的符號,x的值為負、零或正時返回結(jié)果依次為:-1,0或1.

例子:

testdb=# select sign(-21),sign(0),sign(21);

 sign | sign | sign

------+------+------

  -1 |  0 |  1

(1 row)

1.6、冪運算函數(shù)pow(x,y),power(x,y)和exp(x)

pow(x,y),power(x,y)函數(shù)返回x的y次乘方的結(jié)果值;

exp(x)返回e的x乘方后的值;

例子:使用pow,power函數(shù)進行乘方運算,如:

testdb=# select pow(2,2),power(2,2),pow(2,-2),power(2,-2);

 pow | power | pow | power

-----+-------+------+-------

  4 |   4 | 0.25 | 0.25

(1 row)

例子:使用exp(x)返回e的x乘方后的值

testdb=# select exp(3),exp(-3),exp(0);

    exp    |    exp     | exp

------------------+--------------------+-----

 20.0855369231877 | 0.0497870683678639 |  1

(1 row)

1.7、對數(shù)運算函數(shù):log(x)

log(x)返回x的自然數(shù),x相對于基數(shù)e的對數(shù)。對數(shù)定義域不能為負數(shù),因此數(shù)組為負數(shù)將會彈出錯誤信息。

testdb=# select log(3);

    log

-------------------

 0.477121254719662

(1 row)

1.8、角度與弧度相互轉(zhuǎn)換的函數(shù):radians(x)和degrees(x)

radians(x)將參數(shù)x由角度轉(zhuǎn)化為弧度。

如:

testdb=# select radians(90),radians(180);

   radians   |   radians

-----------------+------------------

 1.5707963267949 | 3.14159265358979

(1 row)

degrees(x)將參數(shù)x由弧度轉(zhuǎn)換為角度,如:

testdb=# select degrees(pi()),degrees(pi()/2);

 degrees | degrees

---------+---------

   180 |   90

(1 row)

1.9、正弦函數(shù):sin(x)和反正弦函數(shù):asin(x)

sin(x)返回x正弦,其中x為弧度值。

testdb=# select sin(1),round(sin(pi()));

    sin    | round

-------------------+-------

 0.841470984807897 |   0

(1 row)

asin(x)返回x的反正弦,即正弦為x的值。若x不在-1到1的范圍內(nèi),則會彈出錯誤信息:輸入超出范圍。

1.10、余弦函數(shù):cos(x)和反余弦函數(shù):acos(x)

cos(x)返回x的余弦,其中x為弧度值。

testdb=# select cos(0),cos(pi()),cos(1);

 cos | cos |    cos

-----+-----+------------------

  1 | -1 | 0.54030230586814

(1 row)

acos(x)返回x的反余弦值,即余弦是x的值。若x不在-1到1的范圍之內(nèi),則會彈出錯誤信息。

testdb=# select acos(1),acos(0),round(acos(0.54030230586814));

 acos |   acos    | round

------+-----------------+-------

  0 | 1.5707963267949 |   1

(1 row)

1.11、正切函數(shù):tan(x),反正切函數(shù):atan(x),余切函數(shù):cot(x)

tan(x)返回x的正切,其中x為給定的弧度值。

例子:

testdb=# select tan(0.3),round(tan(pi()/4));

    tan    | round

-------------------+-------

 0.309336249609623 |   1

(1 row)

atan(x)返回x的反正切,即正切為x的值。

例子:

testdb=# select atan(0.309336249609623),atan(1);

 atan |    atan

------+-------------------

 0.3 | 0.785398163397448

(1 row)

cot(x)返回x的余切。

例子:

testdb=# select cot(0.3),1/tan(0.3),cot(pi()/4);

    cot    |   ?column?   | cot

------------------+------------------+-----

 3.23272814376583 | 3.23272814376583 |  1

(1 row)

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

分享題目:postgresql——數(shù)學函數(shù)介紹-創(chuàng)新互聯(lián)
鏈接分享:http://muchs.cn/article10/hidgo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、標簽優(yōu)化、關鍵詞優(yōu)化、服務器托管、定制網(wǎng)站、微信公眾號

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設