我有 aitisi(id、name1、surname1、father1、birthdate1、name2、surname2、father2、birthdate2... 到 5、cost、begins、expires、plan、address、phone、city、zip),我想复制 surnameX , nameX,fatherX,birthdateX (X= 1 to 5) 列到新表成员 (id, tid, name, surname, Father,birthdate) 其中 tid 是 table1.id 的查找键
我用 MySQL 试过,但没有做对,所以我最后用 PHP 做了 id:
$query_aitisi = "SELECT * FROM aitisi order by id asc";
$aitisi = mysql_query($query_aitisi, $connection) or die(mysql_error());
$row_aitisi = mysql_fetch_assoc($aitisi);
$totalRows_aitisi = mysql_num_rows($aitisi);
do {
for($i=1; $i<=5; $i++){
if ($row_aitisi['on_te'.$i]<>'') {
$query_copy = "insert into members (symbid, name, surname, father, birthdate)
values ('".$row_aitisi[id]."','".$row_aitisi['surname'.$i]."','".$row_aitisi['name'.$i]."','".$row_aitisi['father'.$i]."','".$row_aitisi['birthdate'.$i]."')";
$copy = mysql_query($query_copy, $connection) or die(mysql_error());
}
}
} while ($row_aitisi = mysql_fetch_assoc($aitisi));
但是,我真的很想知道正确使用“create table as select”语句以供将来使用。有人吗?谢谢!