I tried to solve 1075. ‘Project Employees I’.

Problem

1075. Project Employees I

problem

Correct Solution

select project_id, round(avg(experience_years),2) as average_years 
  from Project left outer join Employee 
    on Project.employee_id = Employee.employee_id
      group by Project.project_id;

Memo

Round

ROUND(num [ , n ])
  • 1) source
    The source argument is a number or a numeric expression that is to be rounded.
  • 2) n
    The n argument is an integer that determines the number of decimal places after rounding.
    The n argument is optional. If you omit the n argument, its default value is 0.

Ref

_pg_db=# select round(100.00);
 round
-------
   100
(1 row)

_pg_db=# select round(10.123456);
 round
-------
    10
(1 row)

_pg_db=# select round(10.123456, 2);
 round
-------
 10.12
(1 row)

_pg_db=# select round(10.123456, 4);
  round
---------
 10.1235
(1 row)

Agv

Get average

AVG(column)

Ref

_pg_db=# create table t1(a int);
CREATE TABLE

_pg_db=# insert into t1 values (1);
INSERT 0 1
_pg_db=# insert into t1 values (2);
INSERT 0 1
_pg_db=# insert into t1 values (3);
INSERT 0 1
_pg_db=# select avg(a) from t1;
        avg
--------------------
 2.0000000000000000
(1 row)