【问题标题】:SQL Oracle, what is done here?SQL Oracle,这里做了什么?
【发布时间】:2021-10-10 09:53:56
【问题描述】:

谁能告诉我这段代码到底是做什么的? count-function后面的4是什么意思?

SELECT ROUND(SUM(correct)/COUNT(*),4) AS accuracy
  FROM (SELECT DECODE(survived,
               PREDICTION(DT_TITANIC USING *), 1, 0) AS correct
          FROM titanic_test_data);

【问题讨论】:

标签: sql oracle plsql dataminer


【解决方案1】:

它有什么作用?计算平均值并将其四舍五入到小数点后 4 位。

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是表中所有工资的总和
  • num_of_employees 是员工人数
  • average_salary,如sum_salary 除以num_of_employees
  • rounded_avg_salary 是“你的”代码的作用

请注意,我们通常这样做

SQL> select avg(sal) from emp;

  AVG(SAL)
----------
2073,21429

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 2013-06-28
    • 2023-01-19
    • 2020-12-23
    • 1970-01-01
    相关资源
    最近更新 更多