简体   繁体   English

php MySQL得到字符串之间的区别

[英]php MySQL getting difference between strings

My script fulfills the requirement but fires several thousand of queries for this reason, so it take 50-65 seconds. 我的脚本可以满足要求,但是由于这个原因会触发数千个查询,因此需要50-65秒。 I am looking for alternative, more elegant and quick solution. 我正在寻找替代,更优雅,更快捷的解决方案。

SELECT GROUP_CONCAT(DISTINCT BatchNo SEPARATOR ', ') AS picklists, web_company_name
FROM PickBatch 
LEFT JOIN customer_master ON customer_master.VC_CUSTOMER_CODE = PickBatch.Customer
GROUP BY Customer

This returns column Picklists like 4334, 3443, 3341, 4543 这将返回列选择列表,例如4334、3443、3341、4543

After that I have to compare it one by one with another column 之后,我必须将其与另一列进行比较

while( $row=mysql_fetch_array($res) )
{   
     $picklists = explode(', ', $row['picklists']);
     $pickString = '';
     foreach($picklists as $batch)
     {
         //invoiced
         $sql2 = "SELECT invoice_no FROM invoice_web_order WHERE FIND_IN_SET('$batch', frombatch) LIMIT 1";
         $res2 = mysql_query($sql2) or die(mysql_error());
         if ( mysql_num_rows($res2) > 0 )
         {
             continue;
         }   
        $pickString .= "$batch, ";
    }
    echo $pickString;
}

So for example comparing 4334, 3443, 3341, 4543 with, for instance, 3892, 4890, 3341, 2389 from "frombatch" will exclude 3343. 因此,例如,将4334、3443、3341、4543与例如“ frombatch”中的3892、4890、3341、2389进行比较将排除3343。

Are there any other way to do the same? 还有其他方法可以做到吗? So that only 4334, 3443, 4543 will be returned? 这样只会返回4334、3443、4543?

Could you please provide table definition? 您能提供表格定义吗?

SELECT 
    DISTINCT BatchNo as BN, 
    GROUP_CONCAT(DISTINCT BatchNo SEPARATOR ', ') AS picklists, 
    web_company_name
FROM PickBatch
LEFT JOIN customer_master ON customer_master.VC_CUSTOMER_CODE = PickBatch.Customer
WHERE PickBatch.BN <>      (SELECT frombatch 
                            FROM invoice_web_order 
                            WHERE FIND_IN_SET(PickBatch.BN, frombatch)
                            LIMIT 1)
GROUP BY Customer

It seems like you just want to know which Batch numbers exist in PickBatch that doesn't already exist somewhere in the frombatch column in any row in the invoice_web_order table. 似乎您只是想知道PickBatch中存在哪些批号,而invoice_web_order表中任何行的frombatch列中都不存在该批号。

Table: PickBatch
BatchNo
4334
3443
3341
5453

Table: invoice_web_order
frombatch
3982, 4890, 3341, 2389
####, ####, ####
####, ####, ####, ####

SELECT DISTINCT batchno FROM PickBatch LEFT JOIN invoice_web_order ON FIND_IN_SET(batchno, frombatch) WHERE invoice_web_order.frombatch IS NULL

You also did a grouped by CUSTOMER and I'm not sure why. 您还按客户进行了分组,但不知道为什么。 If you explain, I can help with work it into this solution if appropriate. 如果您有解释,我将在适当的情况下帮助您解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM