如何插入选择的值中

时间:2018-12-17 10:25:56

标签: insert insert-into

如何插入选择表,其中值是带有if和else if语句的select语句的结果?
``纳马斯''有4个项目,我想将这些值插入到具有不同值的条件中。

    $sql1 = "SELECT * FROM dbkriteria";
    $result=mysqli_query($con,$sql1) or die("Bad Query : $sql");
    echo"<center><table border='1'></center>";
      echo"<tr><th>Namas</th>
       <th>Nilai Penjualan</th>
       <th>Penjualan Tertagih</th>
       <th>Visit/Presentasi</th>
       <th>Demo Produk</th>
       <th>Lost Project</th>
       <th>Customer Baru</th>
       <th>Cross/Up Selling</th>
       <th>Absen</th>
      </tr>";
   while ($row = mysqli_fetch_assoc($result)) {
    $a = '';
    $b = '';
    $c = '';
    $d = '';
    $e = '';
    $f = '';
    $g = '';
    $h = '';

   if ($row['jumlahtransaksi'] < 2500000000 && $row['jumlahtransaksi'] > 2010000000) {
    $a = 0.706;
}elseif ($row['jumlahtransaksi'] < 2000000000 && $row['jumlahtransaksi'] > 1510000000) {
    $a = 0.415;
}elseif ($row['jumlahtransaksi'] < 1500000000 && $row['jumlahtransaksi'] > 1010000000) {
    $a = 0.225;
}elseif ($row['jumlahtransaksi'] < 1000000000 && $row['jumlahtransaksi'] > 501000000) {
    $a = 0.109;
}elseif ($row['jumlahtransaksi'] < 500000000 && $row['jumlahtransaksi'] > 0) {
    $a = 0.048;
}

   if ($row['statustransaksi'] <= 10 && $row['statustransaksi'] >= 9) {
    $b = 0.559;
}elseif ($row['statustransaksi'] <= 8 && $row['statustransaksi'] >= 7) {
    $b = 0.317;
}elseif ($row['statustransaksi'] <= 6 && $row['statustransaksi'] >= 5) {
    $b = 0.178;
}elseif ($row['statustransaksi'] <= 4 && $row['statustransaksi'] >= 3) {
    $b = 0.092;
}elseif ($row['statustransaksi'] <= 2 && $row['statustransaksi'] >= 1) {
    $b = 0.047;
}   

  if ($row['visit'] <= 10 && $row['visit'] >= 9) {
    $c = 0.511;
}elseif ($row['visit'] <= 8 && $row['visit'] >= 7) {
    $c = 0.290;
}elseif ($row['visit'] <= 6 && $row['visit'] >= 5) {
    $c = 0.172;
}elseif ($row['visit'] <= 4 && $row['visit'] >= 3) {
    $c = 0.103;
}elseif ($row['visit'] <= 2 && $row['visit'] >= 1) {
    $c = 0.052;
}elseif ($row['visit'] <= 0) {
    $c = 0.052;
}

  if ($row['demo'] <= 10 && $row['demo'] >= 9) {
    $d = 0.522;
}elseif ($row['demo'] <= 8 && $row['demo'] >= 7) {
    $d = 0.299;
}elseif ($row['demo'] <= 6 && $row['demo'] >= 5) {
    $d = 0.179;
}elseif ($row['demo'] <= 4 && $row['demo'] >= 3) {
    $d = 0.107;
}elseif ($row['demo'] <= 2 && $row['demo'] >= 1) {
    $d = 0.053;
}elseif ($row['demo'] <= 0) {
    $d = 0.053;
}

  if ($row['lostproject'] <= 0) {
    $e = 0.376;
}elseif ($row['lostproject'] <= 1) {
    $e = 0.233;
}elseif ($row['lostproject'] <= 2) {
    $e = 0.178;
}elseif ($row['lostproject'] <= 3) {
    $e = 0.125;
}elseif ($row['lostproject'] >= 4) {
    $e = 0.088;
}

  if ($row['customerbaru'] >= 5) {
    $f = 0.426;
}elseif ($row['customerbaru'] >= 4) {
    $f = 0.268;
}elseif ($row['customerbaru'] >= 3) {
    $f = 0.156;
}elseif ($row['customerbaru'] >= 2) {
    $f = 0.091;
}elseif ($row['customerbaru'] <=1) {
    $f = 0.059;
}

  if ($row['crossup'] >= 5) {
    $g = 0.416;
}elseif ($row['crossup'] >= 4) {
    $g = 0.262;
}elseif ($row['crossup'] >= 3) {
    $g = 0.161;
}elseif ($row['crossup'] >= 2) {
    $g = 0.099;
}elseif ($row['crossup'] <= 1) {
    $g = 0.062;
}

   if ($row['absen'] <= 20 && $row['absen'] >= 17) {
    $h = 0.403;
}elseif ($row['absen'] <= 16 && $row['absen'] >= 13) {
    $h = 0.255;
}elseif ($row['absen'] <= 12 && $row['absen'] >= 9) {
    $h = 0.166;
}elseif ($row['absen'] <= 8 && $row['absen'] >= 5) {
    $h = 0.108;
}elseif ($row['absen'] <= 4 && $row['absen'] >= 1) {
    $h = 0.067;
}


echo"<tr>
        <td>{$row['namas']}</td>
        <td>{$a}</td>
        <td>{$b}</td>
        <td>{$c}</td>
        <td>{$d}</td>
        <td>{$e}</td>
        <td>{$f}</td>
        <td>{$g}</td>
        <td>{$h}</td>
    </tr>";



  }echo"</table>";

这是我在选择查询中插入的内容,它可以正常工作,但该值无效。

  $sql = "INSERT INTO dbalternatif (id_kriteria,nip,namas,jumlahtransaksi,statustransaksi,visit,demo,lostproject,customerbaru,crossup,absen) SELECT id_kriteria,nip,namas,{$a} as jumlahtransaksi,{$b} as statustransaksi,{$c} as visit, {$d} as demo,{$e} as lostproject, {$f} as customerbaru,{$g} as crossup, {$h} as absen FROM dbkriteria";

   $result=mysqli_query($con,$sql) or die("Bad Query : $sql1");

我希望将表3中的结果插入其他表中:

wrong results

0 个答案:

没有答案