计算 db 中的值 [英] count vales in db
本文介绍了计算 db 中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望将 cvs
上传到数据库中,然后查找数据实例出现的次数以创建选择列表.
I'm looking to upload a cvs
into a db and then find how many times an instance of data appears to create a pick list.
我上传了一个 cvs 到数据库中
I upload a cvs in to the db leaving me with
SKU 和数量
我过去常常从数据库中获取数据,但我无法找到一种方法来对这些数据进行分组,因此每个项目和许多订购项目只有 1 个 sku.
I use to get the data from the db but I cant seam to find a way to group that data so their is only 1 sku for each item and a number of ordered items.
<table border="1" width="100%" id="table1">
<?php
$query = mysql_query("select * from pickcount");
while($fetch = mysql_fetch_array($query))
{
?>
<tr>
<td><?php echo $fetch['sku']; ?></td>
<td><?php echo $fetch['quan']; ?></td>
</tr>
<?php
}
?>
</table>
推荐答案
<table border="1" width="100%" id="table1">
<?php
$query = mysql_query("SELECT sku, SUM(quan) AS Sum_Of_Quan FROM pickcount GROUP BY sku");
while($fetch = mysql_fetch_array($query))
{
?>
<tr>
<td><?php echo $fetch['sku']; ?></td>
<td><?php echo $fetch['Sum_Of_Quan']; ?></td>
</tr>
<?php
}
?>
</table>
尝试用上面的结构替换你的表结构并检查结果
Try to replace your table structure with above structure and check the result
这篇关于计算 db 中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文