title: oracle - case statement and group by
body: <p>Hi – I need your assistance with below query. I’m trying to run the below query below to group by but I get the following error:</p>
  
  <blockquote>
    <p>ORA-00904:” SALES_ID_CO”:invalid identifier</p>
  </blockquote>
  
  <p>Can you please help with this? Many Thanks. </p>
  
  <pre><code>Select
  count(1),
  sales_date,
  CASE 
  WHEN sales_id like '1%'
  THEN substr(sales_id,2,6)
  WHEN sales_id  like '3%'
  THEN substr(sales_id ,2,6)
  WHEN sales_id  like '4%'
  THEN substr(sales_id ,2,6)
  WHEN sales_id  like '5%'
  THEN substr(sales_id ,2,6)
  WHEN sales_id  like '9%'
  THEN substr(sales_id ,1,6)
  WHEN sales_id  like '70%' OR sales_id  like '90%' OR sales_id  like '31%'
  THEN substr(sales_id ,2,6)
  END AS SALES_ID_CO,
  
  case
  WHEN sales_branch like '10%' AND sales_code&lt;&gt; '678 '
  THEN substr(sales_branch,2,6)
  WHEN sales_branch like '200%' AND sales_code&lt;&gt; '678 '
  THEN substr(sales_branch,2,6)
  WHEN sales_branch like '300%' AND sales_code&lt;&gt; '678 '
  THEN substr(sales_branch,2,6)
  WHEN sales_branch like '456%' AND sales_code&lt;&gt; '678 '
  THEN substr(sales_branch,2,6)
  END AS SALES_BRANCH
  
  from tbl_sales_cde
  
  where sales_country IN (‘USA’,’ASIA’,’EU’) 
  group by SALES_ID_CO, SALES_BRANCH,SALES_DATE
  </code></pre>