来自MySQL行的数据乘法 [英] Multiplication of data from MySQL row
本文介绍了来自MySQL行的数据乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够将所有价格乘以例如数据库中的价格,然后将总价格乘以10.
I would like to be able to multiply all the prices for example from my database then multiply the total by 10.
下面的代码执行加法运算而不是乘法运算
The code below do the addition not multiplication
<?php
$d = $_GET['d'];
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("databasename", $con);//
$sql= "SELECT SUM(prices) FROM tablename WHERE Date = '$d' AND Prices >0.20 AND Type= 'sold'";
$results = mysql_query($sql);
$row = mysql_fetch_array($results);
echo $row[0]*10;
mysql_close($con);
?>
示例
id prices
1 25
2 36
3 45
那是我想要25 * 36 * 45 * 10而不是25 + 36 + 45 * 10
That is i want 25*36*45*10 and not 25+36+45*10
希望任何人都可以帮助
推荐答案
这是可行的,但有限制(数字只能为正数):
This would work, with restrictions (numbers should be only positive):
SELECT 10 * EXP(SUM(LOG(prices))) AS result
FROM tablename
WHERE ...
thnx应该转到 Napier
,他的精彩之处发明, logarithms
The thnx should go to Napier
and his wonderful invention, logarithms
这篇关于来自MySQL行的数据乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文