title: Oracle SQL is not a group by expression
body: <p>When I run this code</p>
  
  <pre><code>SELECT sales_date AS DAY, SUM (TOTAL_AMOUNT_RM) 
  
  FROM SALESINVOICE
  
  GROUP BY SALES_DATE
  
  order by sales_date;
  </code></pre>
  
  <p>it gives me a table which is
  <a href="https://i.stack.imgur.com/Tnp45.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>Then I run the other code </p>
  
  <pre><code>SELECT SR.DAY, SUM(SR.PROFIT_RM) AS TOTALPROFIT_RM
  
  FROM
  
  (SELECT SALESINVOICE_ID AS NO, S.ITEM_ID AS ITEM, SALES_DATE AS DAY, S.QUANTITY, C.PRICE_RM, C.COST_RM, ((S.QUANTITY*C.PRICE_RM)-(S.QUANTITY*C.COST_RM)) AS PROFIT_RM
  
  FROM SALESINVOICE S
  
  INNER JOIN (SELECT ITEM_ID, PRICE_RM, COST_RM FROM ITEM I ) C
  
  ON S.ITEM_ID = C.ITEM_ID
  ORDER BY SALESINVOICE_ID, SALES_DATE) SR 
  GROUP BY SR.DAY
  
  ORDER BY SR.DAY;
  </code></pre>
  
  <p>which gave me a table <a href="https://i.stack.imgur.com/yaMI2.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>I try to inner join both table, but when I try to call the column sum(total_amount_rm), it gives me an group by expression error</p>
  
  <pre><code>SELECT SR.DAY, SUM(SR.PROFIT_RM) AS TOTALPROFIT_RM, D.TOTAL
  
  FROM 
  
  (SELECT SALESINVOICE_ID AS NO, S.ITEM_ID AS ITEM, SALES_DATE AS DAY, S.QUANTITY, C.PRICE_RM, C.COST_RM, ((S.QUANTITY*C.PRICE_RM)-(S.QUANTITY*C.COST_RM)) AS PROFIT_RM
  
  FROM SALESINVOICE S
  
  INNER JOIN (SELECT ITEM_ID, PRICE_RM, COST_RM FROM ITEM I ) C
  ON S.ITEM_ID = C.ITEM_ID
  ORDER BY SALESINVOICE_ID, SALES_DATE) SR
  
  INNER JOIN (SELECT SALES_DATE AS DAY, SUM(TOTAL_AMOUNT_RM) AS TOTAL FROM SALESINVOICE GROUP BY SALES_DATE ORDER BY SALES_DATE) D
  
  ON D.DAY = SR.DAY
  
  GROUP BY SR.DAY
  
  ORDER BY SR.DAY;
  </code></pre>
  
  <p>However, it can run without the selection of D.TOTAL. Can anyone help me? I am sql newbie</p>