4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

みんなの為のMySQLまとめ(10)

Posted at

参考
http://homepage2.nifty.com/sak/w_sak3/doc/sysbrd/mysql_13.htm

■絶対値

・abs() 関数は、絶対値を返す。

select abs(-123);

select key1, abs(data1) from testm;


■余り

  ・mod() 関数は、余りを返す。

>```
select mod(123, 10);
select key1, mod(data1, 10) from testm;

■四捨五入

・round() 関数は、四捨五入結果を返す。

select round(10.346, 2);
kobito.1423675268.196075.png

■切り捨て

・truncate() 関数は、切り捨て結果を返す。

select truncate(10.349, 2);

select key1, truncate(data1, 2) from testm;


■スクエアルート

  ・sqrt() 関数は、平方根を返す。

>select sqrt(2.0);
![kobito.1423675446.365277.png](https://qiita-image-store.s3.amazonaws.com/0/59354/3d5a8f5e-308b-ee2a-2b4f-feb7d5651cdf.png "kobito.1423675446.365277.png")

■数値から文字列へ変換 (数値フォーマット、書式変換)

  ・文字列としての結合は concat() を使用する。

>```
select concat(123456, 789012);
select concat('123456', 789012);
select concat('123456', '789012');

kobito.1423675573.425190.png

・三桁毎にカンマを付けるには、次のようにする。

select format(123456, 0);

select format(123456, 2);

![kobito.1423675691.070904.png](https://qiita-image-store.s3.amazonaws.com/0/59354/17efee22-d2d4-59bd-0538-d9484b8ebc55.png "kobito.1423675691.070904.png")

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?