Create a sql view based converting ranges into rows

前端 未结 2 1806
情书的邮戳
情书的邮戳 2020-12-20 01:06

I have a table structured like so

ColA|ColB|LowRange|HighRange
----------------------------
  1   A     1         5

I would like to create

2条回答
  •  醉话见心
    2020-12-20 01:35

    The only way I can figure this one out is by creating a separate table that has all the numbers and then join to the original table. I created a table called 'allnumbs' and it has only one column with the name of 'num' and a record for every number between 1 and 10. Then you join them.

    select cola, colb, b.num from temp a
    join allnumbs b on b.num >= a.lownum and b.num <= a.highnum
    

    Table temp is your table that your displayed. Hope this helps.

提交回复
热议问题