[英]sum all price of the table SQL
如何对表格中的价格行求和,这是我的代码。
$sql=mysql_query("SELECT sum(Price) * FROM reservations as A
inner join service as B on A.Res_ser_ID = B.Ser_ID
inner join personel as C on A.Res_per_ID = C.Per_ID
where Res_cus_ID = '$userID' ");
您需要升级到受支持的软件,例如mysqli_
。 PHP的mysql_ API多年来一直不受支持。 然后,您可以使用参数-安全有效地从应用程序使用SQL的关键。
我认为是这样的(不使用参数):
SELECT sum(s.Price) as sum_price
FROM reservations r JOIN
service s
ON r.Res_ser_ID = s.Ser_ID
WHERE r.Res_cus_ID = '$userID';
假设价格来自service
表。
"select sum(service.price) as sum_price from (reservations inner join
service on reservation.Res_ser_D = service.Ser_ID inner join personnel
on reservation.Res_per_ID = personnel.Per_ID ) where
reservation.Res_cus_ID = '$userID'"
这将起作用,我假设价格已包含在餐桌服务中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.