title: I have a select query inside a select query which throws the error :"more than one row returned by a subquery used as an expression"
body: <p>I am trying to display multiple things such as userid, salary, etc. 
  I used a select statement to do this. In this select statement, i need to use another select statement to provide 'fraction of salaries' . The query of fraction is correct. When i try to use this select into the main select, it gives the error "more than one row returned by.."
  Sample data: </p>
  
  <pre><code>//sample data
  insert into employee(id_user int,salary_date date,salary_value) values 
  (3, 2017-06-28, 15)
  ( 5, 2017-06-26 5)
  ( 2, 2017-06-20 5)
  ( 1, 2017-06-20 15)
  ( 4, 2017-06-17 25)
  
  //expected output:
  id date       sal  newdate   days aboveavgsal     date     current/firstsal 
  1  2017-06-20 15  2017-05-20   31   N           2017-04-20    0.6
  1  2017-05-20 10  2017-04-20   30   N           2017-04-20    0.4
  1  2017-04-20 20  2017-03-20   31   Y           2017-03-20    0.8
  1  2017-03-20 20  2017-02-20   28   Y           NULL          0.8
  1  2017-02-20 15  NULL         NULL N           NULL          0.6
  
      SELECT  id_user
              , salary_date
              , salary_value
              , lead(salary_date) OVER(PARTITION BY id_user ORDER BY salary_date desc)
              , salary_date::timestamp - lead(salary_date::timestamp) over (PARTITION BY id_user ORDER BY salary_date DESC)
              , CASE WHEN salary_value &gt;= 20 THEN 'Y' ELSE 'N' END
              , CASE WHEN salary_value &gt;= 20 THEN lead(salary_date) OVER(PARTITION BY id_user ORDER BY salary_date DESC) END
              , (SELECT CAST(t1.salary_value AS float) / CAST(t.salary_value AS float) 
                 FROM (
                       SELECT  t.id_user
                               , t.salary_value
                               , ROW_NUMBER() OVER(PARTITION BY t.id_user ORDER BY t.salary_date) AS rowrank
                       FROM employee t
                      ) AS t
                      INNER JOIN employee AS t1 ON t1.id_user = t.id_user
                      WHERE t.rowrank = 1
                      GROUP BY t1.id_user, t1.salary_value, t1.salary_date, t.salary_value, t.rowrank
                      ORDER BY t1.id_user, t1.salary_date DESC
                ) AS fraction
      FROM employee
  
  
  Error starts in this query which i tried enclosing in braces.
  
      (SELECT  CAST(t1.salary_value AS float) / CAST(t.salary_value AS float) 
       FROM (
             SELECT t.id_user
                    , t.salary_value
                    , row_number() OVER(PARTITION BY t.id_user ORDER BY t.salary_date ) AS rowrank
             FROM employee t) AS t
             INNER JOIN employee t1 ON t1.id_user = t.id_user
             WHERE t.rowrank = 1
             GROUP BY t1.id_user, t1.salary_value, t1.salary_date, t.salary_value, t.rowrank
             ORDER BY t1.id_user, t1.salary_date DESC
            )
  
  
  </code></pre>