Home > Database > SQL > How to remove the decimal point from sum in sql

How to remove the decimal point from sum in sql

下次还敢
Release: 2024-05-09 09:33:15
Original
657 people have browsed it

How to remove the decimal point of SUM in SQL: Use the ROUND() function: ROUND(SUM(expression), decimal_places) to retain 0 decimal places: ROUND(SUM(salary), 0) Round to the nearest integer ROUND () function only affects the display of query results and does not affect the data in the table. Permanently delete the decimal point: ALTER TABLE employee ALTER COLUMN salary TYPE INT

How to remove the decimal point from sum in sql

## Removed in SQL SUM decimal point

In SQL, you can remove the decimal point from the SUM calculation result by using the ROUND() function.

Syntax:

<code>ROUND(SUM(expression), decimal_places)</code>
Copy after login
Among them:

    expression: the expression that requires the sum.
  • decimal_places: The number of decimal places to retain. If 0, the result will be rounded to the nearest integer.

Usage example:

<code class="sql">SELECT ROUND(SUM(salary), 0) AS total_salary
FROM employee;</code>
Copy after login
This query will calculate the sum of the salary column in table employee and round the result to the nearest integer.

Note:

    ROUND() function only affects the display of query results, not the data in the underlying table.
  • If you want to permanently remove the decimal point, you can use the ALTER TABLE statement to change the data type of the column. For example:
<code class="sql">ALTER TABLE employee ALTER COLUMN salary TYPE INT;</code>
Copy after login
This will change the data type of the salary column to integer, thereby permanently removing the decimal point.

The above is the detailed content of How to remove the decimal point from sum in sql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template