Home > Backend Development > PHP Tutorial > 怎么才能把数据库的中的数据以一个条件查询出来,然后统计里面的另一个字段中存的数据累加一共是多少.

怎么才能把数据库的中的数据以一个条件查询出来,然后统计里面的另一个字段中存的数据累加一共是多少.

不言
Release: 2023-02-28 17:06:02
Original
2806 people have browsed it

有这样一个要求,就是我要先把润安大厦显示出来,然后再统计润安大厦 一共领取了多少台电脑    

回复讨论(解决方案)

读取时自己累加就是了

读取时自己累加就是了  
麻烦您说的具体点...谢谢了!

	$sql="select sum(number) as total where where area='润安大厦'";	
	$result=mysql_query($sql);	
	while($row=mysql_fetch_array($result)){		
	$total=$row['total'];	
	}	
	echo "润安大厦:".$total."台";
Copy after login
Copy after login

还要怎么具体呢?
有数组
array(
array('a', 1),
array('a', 2),
array('b', 1),
array('c', 1),
array('a', 1),
)
现要求按第一列分别对第二列求和,你说该如何做?

还要怎么具体呢?
有数组
array(
array('a', 1),
array('a', 2),
array('b', 1),
array('c', 1),
array('a', 1),
)
现要求按第一列分别对第二列求和,你说该如何做?

		$query = "select * from tbl_apply_register where area = '润安大厦'";		
		$sql = mysql_query($query);		
		while($row = mysql_fetch_array($sql)){			
		$tmp[] = $row[number];			
		}		
		echo array_sum($tmp);
Copy after login
Copy after login

	$sql="select sum(number) as total where where area='润安大厦'";	
	$result=mysql_query($sql);	
	while($row=mysql_fetch_array($result)){		
	$total=$row['total'];	
	}	
	echo "润安大厦:".$total."台";
Copy after login
Copy after login
		$query = "select * from tbl_apply_register where area = '润安大厦'";		
		$sql = mysql_query($query);		
		while($row = mysql_fetch_array($sql)){			
		$tmp[] = $row[number];			
		}		
		echo array_sum($tmp);
Copy after login
Copy after login

$sql="select sum(number) as total where  where area='润安大厦'";  
不好意思,多了个where  
你的方法跟我的本质相同,不过我的是在数据库中直接算出来。

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