[英]Find count from string column with numeric values
I have dataset where the numeric columns are also in string type. 我有数字列也为字符串类型的数据集。
And I need the count of rows where the value is greater than 5 and less than 60. Since it is a string column it has comma separated numbers in it. 而且我需要计数值大于5且小于60的行数。由于它是字符串列,所以其中包含逗号分隔的数字。
The values in database in this column are like 此列中数据库中的值类似于
98,800 40,857.06 5 500 1,250 40
Code: 码:
$rangeQuery = array('NumberInt(this.turnover_GBP_LT)' => array( '$gt' => 5, '$lt' => 100 )); $cursor = $collection->count($rangeQuery);
I am getting the count as 0 though there are values available in the database. 尽管数据库中有可用值,但我将计数设为0。
You can use below php code 您可以使用以下php代码
$numbers = array('98,800',
'40,857.06',
'5',
'500',
'1,250',
'40');
$min = 5;
$max = 100;
$count = count(array_filter(
$numbers,
function ($value) use($min,$max) {
$value = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
return ($value > $min && $value < $max);
}
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.