Uhujkill
Uhujkill

Reputation: 89

SQL: New Column with Calculation Data

Without having to create a new table

I am trying to Create a temporary column, named "New Hourly Pay" (Just for the output) that calculates the Instructors 'Hourly Pay + 10%'.

So I have tried the following,

SELECT Staff_Id, First_Name, Surname, Hourly_Rate AS "Old Hourly Rate", "New_Hourly_Rate"
AS (Hourly_Rate= Hourly_Rate + (Hourly_Rate*.10))
FROM copy_AM_Staff
WHERE Staff_Type = 'Instructor'

But it doesn't have the desired outcome.

Upvotes: 0

Views: 86

Answers (2)

Kermit
Kermit

Reputation: 34055

You're not aliasing the column correctly. You're actually doing it twice.

All you need is:

Hourly_Rate + (Hourly_Rate*.10) AS "New_Hourly_Rate"

Upvotes: 2

potashin
potashin

Reputation: 44581

At first you should do manipulations with the column values and only after that assign an alias to it :

SELECT Staff_Id
     , First_Name
     , Surname
     , Hourly_Rate AS "Old Hourly Rate"
     , (Hourly_Rate*1.10) AS "New_Hourly_Rate"
FROM copy_AM_Staff
WHERE Staff_Type = 'Instructor'

Upvotes: 2

Related Questions