title: Using DB2 column alias within same select
body: <p>I have a working query but I'm trying to use the column aliases in order to create more calculations in my select and it says the column can't be found (i.e. it can't use the alias).</p>
  
  <p>For instance, the working query:</p>
  
  <pre><code>select employee,
         sum(case when date_field between '2018-01-01' and '2018-01-31' and category = 'CategoryOne' then salesprice else 0 end) as priorDate,
         sum(case when date_field between '2018-01-01' and '2018-01-31' then salesprice else 0  end) as priorTotal,
         cast(Round((DEC(sum(case when date_field between '2018-01-01' and '2018-01-31' and category = 'CategoryOne' then salesprice else 0 end),12,2)/sum(case when date_field between '2018-01-01' and '2018-01-31' then salesprice else 0  end)) * 100,2) as decimal(12,2)) as priorPercent,
         sum(case when date_field between '2019-01-01' and '2019-01-31' and category = 'CategoryOne' then salesprice else 0 end) as currentDate,
         sum(case when date_field between '2019-01-01' and '2019-01-31' then salesprice else 0 end) as currentSales,
         cast(Round((DEC(sum(case when date_field between '2019-01-01' and '2019-01-31' and category = 'CategoryOne' then salesprice else 0 end),12,2)/sum(case when date_field between '2019-01-01' and '2019-01-31' then salesprice else 0  end)) * 100,2) as decimal(12,2)) as currentPercent
  from table
  group by employee;
  </code></pre>
  
  <p>But for my two percentages (the two rows that start with cast) I've tried using just <code>priorDate / priorTotal</code> but it won't work and so I have to repeat the 2 whole calculations as a percentage.</p>
  
  <p>I want to also obtain a difference in percentages which would be much easier to declare by using the aliases, and maybe more performant?</p>