怎么求MYSQL字段最小值

WBOY
Release: 2016-06-13 13:44:40
Original
881 people have browsed it

如何求MYSQL字段最小值
require('dbconnect.php');
$query1 = "SELECT min(score) FROM test";  
$result1 = mysql_query("$query1")or die(mysql_error());
$row1 = mysql_fetch_array($result1);
print_r($row1);
?>
但是却打印出下面这句话
Array ( [0] => 1 [min(score)] => 1 ) 
和我想要的结果差好远哦,究竟怎么样写才是对的?

------解决方案--------------------
mysql_fetch_array(data,array_type)
参数 描述
data 可选。规定规定要使用的数据指针。该数据指针是 mysql_query() 函数产生的结果。
array_type
可选。规定返回哪种结果。可能的值:
MYSQL_ASSOC - 关联数组
MYSQL_NUM - 数字数组
MYSQL_BOTH - 默认。同时产生关联和数字数组
你需要设置第二个参数。
------解决方案--------------------
SELECT * FROM test where score=min(score);
------解决方案--------------------
取整行的话,你可以
select * from test where score=min(score);
或者
select * from test order by score ASC limit 1;
..
------解决方案--------------------
SELECT min(字段1)AS min_字段1,MIN(字段2) AS min_字段2,MIN(字段3) AS min_字段3,MIN(字段4) AS min_字段4,FROM 表 where 
得到的结果就是你想要的了
 
------解决方案--------------------
补充一下 ,如果这个表的得到的最小数据想要转存到另外一张表里面可以建立一个存储过程或者去建立一个视图.这个自己去看看手册吧.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!