Forum Discussion
Schuss27
Apr 28, 2023Copper Contributor
Occurrence in an excel serie
Hello, I have an excel column filled with 0 and 1. I would like to count the number of successive 1 and 0 Ex: 011001011100000 The result could be something like 2 columns, I. E the first for 0 an...
peiyezhu
Apr 30, 2023Bronze Contributor
By sql:
cli_add_php~~$GLOBALS['f']=function($origValues){
preg_match_all('{0+}',$origValues,$arrZero);
$arrZeroCount=array_map(function($v){
return strlen($v);
},$arrZero[0]);
$zeroCount=implode(' ',$arrZeroCount);
preg_match_all('{1+}',$origValues,$arrZero);
$arrZeroCount=array_map(function($v){
return strlen($v);
},$arrZero[0]);
$zeroCount.='</td><td>'.implode(' ',$arrZeroCount);
return $zeroCount;
};
~;
select *,udf_run_php(F_A,'$a=$GLOBALS["f"]($origValues);') `0</th><th>1` from Occurrence_in_an_excel_serie;