Posted on May 21, 2010.
SQL how to handle it? I came into this SQL command for a specific answer, I had the answer, but it is too long how can I shorten it, if anyone knows it would be nice ...
Code input:
SELECT ENAME, JOB, SAL, COMM, SAL COMM +, 100 * (COMM / (SAL + COMM)) From EMP WHERE COMM IS NOT NULL;
Result "100 * (COMM / (SAL + COMM))" = 52.830188679245283018867924528301886792 ...
How can I reduce this to perhaps = 52.8301.
Please help, thank you ...
try this:
SELECT ENAME, JOB, SAL, COMM, SAL COMM + ROUND (100 * (COMM / (SAL + COMM)), 4) EMP WHERE COMM IS NOT NULL;
SELECT ROUND (blah, 4) would circle the answer to 4 decimal places (where blah = expression). Or TRUNC (blah, 4) it would truncate the first four digits after the decimal point.
SELECT ENAME, JOB, SAL, COMM, SAL + COMM
CAST (100 * (COMM / (SAL + COMM)) AS DECIMAL (8,4)) From EMP WHERE COMM IS NOT NULL