November 29, 2014 21:01:01
Scenario: Sometimes there are very many discontinuous values in the select in statement that query the database, which can affect query efficiency
Method: Convert a select in query into multiple select between and statements
Code: Core code (ID to sort order)
1 Public functionGroup()2 {3 //$a = array (1,2,3,5,7,8,9);4 $a=Array(1,3,4,5,7,8,9);5 $len=Count($a);6 $cur= 0;//subscript of the currently traversed element7 $pre=$a[0]; The value of the previous element8 9 $new=Array(' 0 ' + =Array($a[0]));Ten for($i= 1;$i<$len;$i++) { One if(($a[$i] -$pre) = = 1 ) { A $new[$cur][] =$a[$i]; -}Else { - $cur=$i; the $new[$cur][] =$a[$i]; - } - $pre=$a[$i]; - } + - Print_r($new); +}
Results
1 Array2 (3[0] = =Array4 (5[0] = 16 )7 8[1] = =Array9 (Ten[0] = 3 One[1] = 4 A[2] = 5 - ) - the[4] = =Array - ( -[0] = 7 -[1] = 8 +[2] = 9 - ) + A)
MySQL in query optimization