mysql - 找到子查询的总和

标签 mysql

查询需要找到一个叫Yossi Cohen的客户,他购买了一些商品以及购买的账单金额(总和) 例如:Yossi Cohen 买了三件值(value) 40 谢克尔的商品,我们想知道订单的金额。

例子:

namecustomer  namemodel  quantity  sum
Yossi Cohen    iphone6      3      120

我试着写这个:(不工作)

SELECT nameCustomer,
   (SELECT idCustomer,nameCustomer,nameModel,idOrders,Quantity,
   SUM(price*Quantity)AS OrderTotal
   FROM Customers,OrdersItems,Products GROUP BY idOrders)
FROM Customer
 where Customer = 'Yossi Cohen';

最佳答案

这应该可以完成工作:

SELECT idCustomer,nameCustomer,nameModel,idOrders,Quantity
From Customer
Where sum=price*Quantity 
AND   Customer = 'Yossi Cohen';

关于mysql - 找到子查询的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36555325/

相关文章:

php - MySQL 将 PHP cron 作业 SQL 合并到一个查询中可能吗?

php - 如何使用 PHP 高效地将数百万个数据集插入 MySQL 数据库?

mysql - 来自数据库的 iOS 多语言

不使用 View 的 MySQL 语句求列的总和和百分比

php - 增加发票 ID 的最佳方法是什么?

php - 限制每日访问

mysql - Grails MySQL 连接

php - 如何检测 MySQL 中的隐式提交?

php - 使用 php 和 mysql 进行搜索

mysql - Access : How to structure input vs read only forms