繁体   English   中英

Mysql查询最小值到最大值

[英]Mysql query for min to max values

mysql DB有一个包含2列的表作为Name和values。 我想要显示从min到max的值,但如果某个名称的值为零,我想跳过该值。

由于您在一个字段中存储了多个名称,然后在另一个字段中存储了相应的值,因此您应该将逻辑移动到PHP。

循环遍历结果集时,每行:

//create arrays of the comma separated fields
$keys   = explode(",", $row['name']);
$values = explode (",", $row['value']);

//combine them & flip since you want to use the values as keys and the keys as values
$combined = array_combine($values, $keys);

//sort by value (which has become a key)
ksort($combined);

// you should now have an array looking like:
// array(0 => "d", 1 => "c", 2 => "b", 5 => "a");
// now let's remove the 0 value
unset($combined[0]);

//debug to make sure this is what you want
print_r($combined);

暂无
暂无

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

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