MySQl查询词的缩写

时间:2018-09-06 14:18:13

标签: php mysql

我想从不同的值中收集两个不同的tabloda。此过程花费的时间太长,因为记录数太大。如何加快查询速度?

表1:sf_uretim10

表2:sf_urun10

<?php 
$query = $db->get_results("SELECT uretimid,urunadi,uretimharid,urunid,cariid,paketsayisi,boy,tonaj,pakettipi,uretimtipi,uretimyeri FROM sf_uretim10 WHERE (durumu='Siparis' OR durumu='URETIMDE') AND cariid > 4  AND sil !=2 ORDER BY urunadi ASC");
?>
<table id="example"> 
    <thead> 
        <tr> 
            <th>Name</th>
            <th>Total A</th>
            <th>Total B</th>
            <th>Total C</th> 
        </tr> 
    </thead> 
    <tbody> 
<?php 
foreach ($query as $row ){
        $total_a = $db->get_var("SELECT SUM(tonaj) FROM sf_urun10 WHERE urunid='$row->urunid' AND tonaj='$tonaj' AND boy='$row->boy' AND (durumu='GIRIS' OR durumu='HATALI') AND cariid < 4 AND sil !=2");
        $total_b = $db->get_var("SELECT SUM(tonaj) FROM sf_urun10 WHERE uretimharid='$row->uretimharid' AND cariid='$row->cariid'  AND (durumu='GIRIS' OR durumu='HATALI') AND sil !=2 ");
        $total_b = $db->get_var("SELECT SUM(tonaj) FROM sf_urun10 WHERE uretimharid='$row->uretimharid' AND cariid='$row->cariid'  AND (durumu='CIKIS') AND sil !=2 ");
?>      
        <tr> 
            <td><?php echo $row->urunadi; ?></td>
            <td><?php echo $total_a; ?></td>
            <td><?php echo $total_b; ?></td>
            <td><?php echo $total_c; ?></td> 
        </tr> 
<?php  }  ?>
    </tbody>

谢谢

0 个答案:

没有答案