MYSQL完全手册学习札记(第七章)

MYSQL完全手册学习札记(第七章)

MYSQL完全手册学习笔记(第七章)

MYSQL函数

mysql> select round(10.33),round(64.50001),round(10.98547);

+————–+—————–+—————–+

| round(10.33) | round(64.50001) | round(10.98547) |

+————–+—————–+—————–+

|           10 |              65 |              11 |

+————–+—————–+—————–+

1 row in set (0.00 sec)

Round 函数四舍五入

mysql> select truncate(1.78502356,3),truncate(-6235.3256984,10);

+————————+—————————-+

| truncate(1.78502356,3) | truncate(-6235.3256984,10) |

+————————+—————————-+

|                  1.785 |           -6235.3256984000 |

+————————+—————————-+

1 row in set (0.00 sec)

mysql> select truncate(1789.09854,-2),truncate(-629.6953245,-1);

+————————-+—————————+

| truncate(1789.09854,-2) | truncate(-629.6953245,-1) |

+————————-+—————————+

|                    1700 |                      -620 |

+————————-+—————————+

1 row in set (0.00 sec)

Truncate 把一个数字截短成为一个指定小数个数的数字,注意取负数的时候哦

mysql> select abs (-789);

+————+

| abs (-789) |

+————+

|        789 |

+————+

1 row in set (0.00 sec)

Abs绝对值

mysql> select * from toys;

+—-+—————–+——-+——-+——-+———-+

| id | item            | ctm   | ctr   | ctc   | quantity |

+—-+—————–+——-+——-+——-+———-+

|  0 | ww              |  3.00 |  3.00 |  3.00 |      200 |

|  1 | huggy bear      |  5.00 |  7.40 |  9.90 |      300 |

|  2 | coloring book   |  3.00 |  5.00 |  7.99 |     2000 |

|  3 | board game      | 12.00 | 20.00 | 39.90 |     1430 |

|  4 | activity cd-rom |  2.00 |  6.00 | 17.49 |     3780 |

|  6 | ww              |  6.00 |  6.00 |  6.00 |      100 |

+—-+—————–+——-+——-+——-+———-+

6 rows in set (0.00 sec)

mysql> select * from toys group by item;

+—-+—————–+——-+——-+——-+———-+

| id | item            | ctm   | ctr   | ctc   | quantity |

+—-+—————–+——-+——-+——-+———-+

|  4 | activity cd-rom |  2.00 |  6.00 | 17.49 |     3780 |

|  3 | board game      | 12.00 | 20.00 | 39.90 |     1430 |

|  2 | coloring book   |  3.00 |  5.00 |  7.99 |     2000 |

MYSQL完全手册学习札记(第七章)

相关文章:

你感兴趣的文章:

标签云: