Agga Agga - 1 year ago 62
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 Source

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().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download