0

I'm trying to build a query and know I'm missing something simple to have a column I'm calling increase produce a difference between ProposedWages and curWages, then order them in descending order on the Increase column. My output is only giving me the negative of the curWages column. See below and TIA for any input you can offer! Update: I took out '' around Increase as suggested, but still not getting the desired outcome for that column.

SELECT 2015payroll.strstore, strTitle, curWages, (curWages * 1.03) AS 'ProposedWages', ('ProposedWages' - curWages) AS 'Increase'
FROM 2015payroll
JOIN 2015sales
ON 2015payroll.strstore = 2015sales.strStore
WHERE strTitle ='Manager' AND cur2015 > cur2014
ORDER BY 'Increase' DESC;

output

  • Don't put `Increase` in quotes. – Barmar Jun 27 '22 at 23:00
  • Thanks. That still gave me the result of that column as the Negative of curWage, although it did get the descending part cleaned up. – Nathan Paris Jun 27 '22 at 23:06
  • `('ProposedWages' - curWages)` is trying to subtract `curWages` from a string. When the string is converted to a number, it becomes `0`, so you get the negative. – Barmar Jun 27 '22 at 23:11
  • If you're trying to refer to `(curWages * 1.03) AS 'ProposedWages'`, you can't refer to a column alias in the same `SELECT` list. Use `(curWages * 1.03) - curWages` or simply `curWages * 0.03` – Barmar Jun 27 '22 at 23:12
  • You don't need to put the aliases in quotes unless they contain special characters or reserved words. – Barmar Jun 27 '22 at 23:13
  • Thanks @Barmar! I knew it was something that I was overthinking. Worked like a charm! – Nathan Paris Jun 27 '22 at 23:16

0 Answers0