通过sql

时间:2016-02-05 13:44:05

标签: sql

我将选项值和类别存储在表格中。

我希望获得一个包含所有可能的选项值组合的列。

例如:

  • 选项类别ID为(1,2,5)
  • 选项值为{(31,39,55),(61,62),(98,99)}

我想要一个这样的列表,在一栏中:

31
61
98

31
61
99

31
62
98

31
62
99

39
61
98

39
61
99

39
62
98


39
62
99

55
61
98

55
61
99

55
62
98

55
62
99

请参见下面的截图

enter image description here

1 个答案:

答案 0 :(得分:0)

不是答案,只需留在这里供你使用

您显示的架构,数据样本和查询。

select b1.cat 'a', b2.cat 'b', b3.cat 'c'  from #b b1, #b b2, #b b3, #a a1 
where a1.id=b1.id and b2.id>a1.id and b3.id>a1.id and b3.id>b2.id
    and b1.cat<b2.cat and b2.cat<b3.cat
order by b1.cat, b2.cat, b3.cat 

这将检索您要查找的一行树项目,以便您需要

for

我会回来的

相关问题