Agga Agga - 4 months ago 14
SQL Question

Add increments of 10 to a select query in SQL

I need to get target values (which needs to be auto incremented by 10, starting from 0) in SQL along with the results that I am already fetching in my Query.

Basically it needs to be a logic like:

set @target =0


and in my display query:

display -> @target = @target +10


Thanks for your help.

Answer

If you want a column that increments by 10, use row_number():

select (10 * (row_number() over (order by (select null)) )) as count_10
from t;

If you have an order by in your query, you should use the same order by for row_number().