title: Invalid operation: subquery must return only one column — Amazon Redshift
body: <p>i have pasted an image with wat o/p i need hope tht helps</p>
  
  <p><a href="https://i.stack.imgur.com/xCZtV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xCZtV.png" alt="enter image description here"></a></p>
  
  <p>I am trying to calculate the percentage of individual rows with total of one particular column.</p>
  
  <p>I am able to achieve it in the <code>SELECT</code> statement with alias name but I have further calculation with the help of column <code>per</code> where I derive other columns, so I need this to be in an <code>UPDATE</code> query. I tried the below query but am getting the error:</p>
  
  <blockquote>
    <p>Invalid operation: subquery must return only one column</p>
  </blockquote>
  
  <p>I don't have any unique id. I cannot use <code>IN</code> statements in this. </p>
  
  <p>Where am I going wrong?</p>
  
  <pre><code>UPDATE a
  SET per = (SELECT DISTINCT
               code,
               p,
               pd,
               ratio_to_report(SUM(amnt)) OVER (PARTITION BY p) AS per
             FROM a 
             GROUP BY code,p,pd
             )
  WHERE per IS null;
  </code></pre>