title: Why is this nested INNER JOIN not working in POSTGRESQL?
body: <p>I am using the Nothwind data base &amp; working in pgAdmin, and my query is looking like this at the moment</p>
  <pre><code>SELECT 
      TO_CHAR (o.ShippedDate, 'yyyy.MM') AS Month 
      ,o.OrderID
      ,Total
      ,SUM (Total) OVER PARTITION BY TO_CHAR (ShippedDate, 
      ‘yyyy.MM’) ORDER BY O.OrderID) AS Running_Total 
  FROM public.orders O
  INNER JOIN (
    SELECT OrderID, SUM(Quantity*UnitPrice) AS Total 
    FROM public.order_details 
    GROUP BY OrderID 
    ORDER BY OrderID
  ) OD ON O.OrderID = OD.OrderID
  WHERE
      TO_CHAR (o.ShippedDate, 'yyyy.MM') IS NOT NULL
  </code></pre>
  <p>And is is not working, it says:</p>
  <blockquote>
  <p>ERROR:  column &quot;o.shippeddate&quot; must appear in the GROUP BY clause or be used in an aggregate function <br />
  LINE 2:  TO_CHAR (o.ShippedDate, 'yyyy.MM') AS Month</p>
  </blockquote>
  <p>Can you help me out what could be the issue? Thanks!</p>
  <p><strong>I fixed the query, so it is now the correct one.</strong></p>