如何生成动态加载的数据库的所有可能结果? [英] how can I generate all possible outcomes of a dynamically loaded database?

查看:32
本文介绍了如何生成动态加载的数据库的所有可能结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我在这个问题上遇到了一些麻烦..

Hi guys I'm having a bit of trouble with this one..

我需要生成这样一个动态加载的数据库的所有可能结果..

I need to generate all possible outcomes of a dynamically loaded database like this one..

COLOUR  SIZE    FABRIC
blue    small   denim
red     medium  cotton
green   large   wool

好的..例如这个数据库(上面)由用户设置,可以添加行和列,所以我不知道我正在处理多少行/列.

ok.. so for example this database (above) gets set up by the user the rows and columns can be added so I don't know how many rows/columns I'm dealing with.

如果它只是 3 列 x 行数,我可以设置一个 for 循环,即继续添加 x 直到它通过所有行,然后增加 y 直到它通过所有列,然后增加 z 等等......

If it was just 3 columns by x amount of rows I could just set up a for loop i.e. keep adding x until it goes though all rows, then increment y until that goes though all columns, then increment z etc...

但是由于我不知道数据库中有多少行,所以我找不到引用数组的方法..

But being as I don't know how many rows are in the database I can't find a way of referencing the array..

我希望我已经对自己进行了充分的解释,让您能够理解,我对编程还很陌生,我一直在努力解决这个问题好几个小时.

I hope I've explained myself well enough for you to understand, I'm pretty new to programming and I've been trying to figure this one out for hours.

推荐答案

JOIN = 笛卡尔积

JOIN = Cartesian product

select * from 
(select distinct colour from TBL) as t1 join 
(select distinct size from TBL)   as t2 join 
(select distinct fabric from TBL) as t3
order by colour, size, fabric;

这篇关于如何生成动态加载的数据库的所有可能结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆