0

Can someone telle me what this code exactly does? What does the 4 mean after count-function?

SELECT ROUND(SUM(correct)/COUNT(*),4) AS accuracy
  FROM (SELECT DECODE(survived,
               PREDICTION(DT_TITANIC USING *), 1, 0) AS correct
          FROM titanic_test_data);
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Eminos
  • 1
  • 1

1 Answers1

0

What does it do? Calculates an average and rounds it to 4 decimals.

SQL> select sum(sal) sum_salary,
  2         count(*) num_of_employees,
  3         --
  4         sum(sal) / count(*) average_salary,
  5         --
  6         round(sum(sal) / count(*), 4) rounded_avg_salary
  7  from emp;

SUM_SALARY NUM_OF_EMPLOYEES AVERAGE_SALARY ROUNDED_AVG_SALARY
---------- ---------------- -------------- ------------------
     29025               14     2073,21429          2073,2143
  • sum_salary is sum of all salaries in the table
  • num_of_employees is number of employees
  • average_salary, as sum_salary divided by num_of_employees
  • rounded_avg_salary is what "your" code does

Note that we usually do it as

SQL> select avg(sal) from emp;

  AVG(SAL)
----------
2073,21429
Littlefoot
  • 131,892
  • 15
  • 35
  • 57