如何根据第一列填充列
我正在制作一个 mySQL 表,其中列出了大约 70 种产品以及它们是否兼容的信息。为了简化问题,我假设只有四种产品。
Product1 Product2 Compatible?
A A Yes
A B No
A C Maybe
A D Yes
B A Yes
B B Yes
B C Yes
B D No
C A Yes
C B Maybe
C C Yes
C D Yes
D A Yes
D B No
D C Yes
D D Yes
如果我已经有一个类似的表格(每个产品显然都与其自身兼容),
Product1 Product2 Compatible?
A A Yes
B B Yes
C C Yes
D D Yes
有没有办法可以快速填写前两列,以便它们遵循正确的模式? (所以我不必手动完成)
I am making a mySQL table which lists ~70 products and information on whether they are compatible or not. For the sake of simplifying the question, I will pretend there were only four products.
Product1 Product2 Compatible?
A A Yes
A B No
A C Maybe
A D Yes
B A Yes
B B Yes
B C Yes
B D No
C A Yes
C B Maybe
C C Yes
C D Yes
D A Yes
D B No
D C Yes
D D Yes
If I already have a table like (every product is obviously compatible with itself)
Product1 Product2 Compatible?
A A Yes
B B Yes
C C Yes
D D Yes
Is there a way I can quickly fill out the first two columns so they follow the correct pattern? (so I dont have to be doing it manually)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实现此目的的一种方法是使用嵌套循环:如果您知道您有多少个产品,我们将其称为 n 个产品。
您的表中将总共有 2^n 行。此外,产品 1 的每个库存项目都会有 n 次。 (在您的示例中,有 4 个项目,因此 2^4 = 16 行,每个项目在 Product1 列中出现 n=4 次。
因此可以实现嵌套循环来执行插入...
One way to do this would be to use nested loops: If you know how many products you have, lets call it n products.
2^n total rows will be in your table. Additionally, product 1 will have each inventory item n times. (In your example 4 items, so 2^4 = 16 total rows and each item occurs in product1 column n=4 times.
Thus a nested loop can be achieved to do the insert...
插入后触发器!
当使用 phpMyadmin 插入时,将该列留空。让触发器填充最后一列。
Insert-After triggers!
And when inserting with phpMyadmin leave the column blank. let the trigger fill last column.
根据您的第二个列表,我假设您已经让它们与自身兼容。
I assumed that you already have them compatible with themselves, based on your second list.