0

Possible Duplicate:
generate an integer sequence in MySQL
generate many rows with mysql

Is there a (simple) mean to create an sql request that return integers between 1 and N ? ( like a range(n) in python. )

Something like :

select i 
FROM all_ints_values  
where i >= 1 and i < N;

where table all_ints_values should contains all ints values !!

Of course it souldn't be possible to create such a table. (and even if N is limited I don't want do this)

Context :

I've got a table with sales ( dated by year and month). I want to retrieve the sum of sales by year and mounth. You can do that with a group by close :

select year,month, sum(money) from my_table group by year,month order by year,month

But with this I get 'holes' in my list ( if there is no sales in January 2011) so it not suitable to make a graph.

With the generator I could use an OUTER JOIN some thing like:

select y.i,m.i, nvl(sum_money,0) LEFT OUTER JOIN mysummaryview ON y.year = year and m.month = month FROM (select int from 1990 to 2012) y , (select int from 1 to 12) m order by y.i,m.i
Community
  • 1
  • 1

0 Answers0