Lithicas
Lithicas

Reputation: 4013

SQL, incrementing column value returned from SELECT query

SELECT x, y, z FROM table_one
WHERE y='asd'
ORDER BY z ASC;

Hi, I'm querying my database using the query above, upon the return of the query I'd like to increment z by 1 (not update it but just increment it so it shows in the result). I don't want to do an Update statement, this is just temporary and should only be visible in the query result.

How would I go about doing this? It's for a school assignment. I've tried to use REPLACE without any success. What works is changing z to z+1 but then the column name changes to ?column? instead of z.

Any help would be appreciated!

Upvotes: 1

Views: 38

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175566

You need add column alias:

SELECT x, y, z + 1 AS z    -- here
FROM table_one
WHERE y='asd'
ORDER BY z ASC;

Upvotes: 3

Related Questions