zoukankan      html  css  js  c++  java
  • mysql 临时表代替in的方法

    mysql 临时表代替in的方法

        public function infengzhuang($ziduanstr = '', $table = '',$whereziduan='',$instr = '', $wherestr = '')
        {
            $haomiao = $this->get_millisecond();
            if (empty($instr)) {
                $sql     = 'select ' . $ziduanstr . ' from ' . $table . $wherestr;
                $tmplist = $this->commongetinfo($sql);
            } else {
                $inattr       = explode(',', $instr);
                $repairinattr = array();
                foreach ($inattr as $k => $v) {
                    $repairinattr[] = '(' . $v . ')';
                }
                $repairinstr = join(',', $repairinattr);
    
                $sql = 'create temporary table tmp' . $haomiao . '(id int(4) primary key)';
    
                $this->commonexecute($sql);
                $sql = 'insert into tmp' . $haomiao . ' values ' . $repairinstr;
      
                $this->commonexecute($sql);
                if (!empty($wherestr)) {
                    $wherestr = ' and  ' . $wherestr;
                }
                // $sql='select * from tmp' . $haomiao;
                // $list=$this->commongetinfo($sql);
                // print_r($list);
                // exit();
                $sql = 'select ' . $ziduanstr . ' from ' . $table . ',tmp' . $haomiao . ' where ' . $table . '.'.$whereziduan.'=tmp' . $haomiao . '.id' . $wherestr;
             
                $tmplist = $this->commongetinfo($sql);
                   
             
            }
    
            return $tmplist;
        }

    当然也可以直接返回临时表 

     $wheredingdanstr = 'dingdanleixing="销售订单"';
    
    $dianpuid='2,3,4'
    
        $dingdanlists = $this->infengzhuang('fukuanquerenshijian,dingdan,jiesuanprice,shangpinid,dingdanzhuangtai,shangjiabeizhu,dianpuid ', $tablelist['dingdanlist_table'],'dianpuid',$dianpuid,$wheredingdanstr);


    如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
    作者:newmiracle
    出处:https://www.cnblogs.com/newmiracle/

     
  • 相关阅读:
    169. Majority Element
    283. Move Zeroes
    1331. Rank Transform of an Array
    566. Reshape the Matrix
    985. Sum of Even Numbers After Queries
    1185. Day of the Week
    867. Transpose Matrix
    1217. Play with Chips
    766. Toeplitz Matrix
    1413. Minimum Value to Get Positive Step by Step Sum
  • 原文地址:https://www.cnblogs.com/newmiracle/p/15355803.html
Copyright © 2011-2022 走看看