0

我有几张表,前三行相同,其余的不同(数字也是如此)。我想将所有表合并为一个,前三列保持原样,其余列连接在一起,形成一个名为“描述”的列。现在,我可以手动执行此操作,但我有很多表。可以使用带有变量的while循环吗?还是可行的?

4

1 回答 1

0

It sounds like you want to join the tables together. In MySQL, this would look like:

select t1.col1, t1.col2, t1.col3,
       concat(t1.col4, t2.col4, t3.col4) as description
from t1 left outer join
     t2
     on t1.col1 = t2.col1 and t1.col2 = t2.col2 and t1.col3 = t2.col3 left outer join
     t3
     on t1.col1 = t3.col1 and t1.col2 = t3.col2 and t1.col3 = t3.col3
于 2013-11-07T16:33:42.817 回答