IBM’s DB2 database management software uses the Structured Query Language, or SQL, to create and manage database structures and update the information in them. SQL is an industry-standard programming language that includes mathematical functions for performing detailed analyses on database data. Using SQL, you can easily compute percentages for each record of a database table, for groups of records and for table totals. SELECT name, order_number, item_total, item_total * 100 / order_total AS percentage FROM order_table; If you calculate percentages based on integer fields, multiplying the first item by 100 ensures that a subsequent division returns a meaningful percentage. If you instead divide an integer by a bigger integer and multiply the result by 100, SQL returns a zero. SELECT name, order_number, DECIMAL(item_total, item_total * 100.0 / order_total,5,2) AS percentage, order_total FROM order_table; The DECIMAL function has three arguments: the number or calculated value, the number of digits for precision and the number of digits after the decimal. Here, the precision is five and the number of digits after the decimal is two. This SELECT statement produces a percentage as a number having five total digits and two decimal places, such as 56.05 or 199.10. Writer Bio
