简体   繁体   中英

find Sum of Sub-Query

Query need to find a client named Yossi Cohen, who purchased a number of items and the amount billed(sum) of purchase For example: Yossi Cohen bought three items costing 40 shekels and we want to know the amount of the order.

example:

namecustomer  namemodel  quantity  sum
Yossi Cohen    iphone6      3      120

I try to write this:(not working)

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';

This should do the work:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM