Embedded SQL statement in ACCESS (急)20分

2008-07-01 4:14 pm
請問點寫SQL statement , 可以從 Database 中計數:

Database 有訂單記錄了每次的產品名稱, 產品數量, 產品價錢.
Total amount = 把每款產品的數量 x 價錢加起來

現要寫SQL statement, 計出Total Amount.

但我唔識點可以抽出產品數量, 產品價錢, 再乘和加

回答 (1)

2008-07-04 7:46 am
✔ 最佳答案
I think you are using Access VBA. Is Order_number.Value a textbox on a form?

Your sql statement looks like this:

SELECT SUM( [ORDER-PRODUCT].Quantity * PRODUCT.Unit_price) AS Total_Amount
FROM PRODUCT INNER JOIN [ORDER-PRODUCT] ON PRODUCT.[Product code]=[ORDER-PRODUCT].[Product code]
WHERE [ORDER-PRODUCT].[order number] =' " & Order_number.Value & " ' ;"

This sql statement returns you the total amount of all products on ONE order.

2008-07-04 05:18:53 補充:
不能同上面的 sql statement 一齊做,要分開做,因為上面的 sql 是將不同的產品加在一起計算總值,現在要每一產品逐一比較。

2008-07-04 05:25:50 補充:
SELECT [ORDER-PRODUCT].[order number], [ORDER-PRODUCT].[Product code],
PRODUCT.[Stock Quantity] - [ORDER-PRODUCT].Quantity AS Surplus
FROM PRODUCT INNER JOIN [ORDER-PRODUCT]
ON PRODUCT.[Product code]=[ORDER-PRODUCT].[Product code]
WHERE [ORDER-PRODUCT].[order number] =' " & Order_number.Value & " ' ;"

2008-07-04 05:26:06 補充:
Surplus < 0 => out of stock

2008-07-04 05:28:59 補充:
SELECT [ORDER-PRODUCT].*
FROM PRODUCT INNER JOIN [ORDER-PRODUCT]
ON PRODUCT.[Product code]=[ORDER-PRODUCT].[Product code]
WHERE PRODUCT.[Stock Quantity] > [ORDER-PRODUCT].Quantity
AND [ORDER-PRODUCT].[order number] =' " & Order_number.Value & " ' ;"

2008-07-04 05:30:24 補充:
Only orders with sufficient stock are returned.


收錄日期: 2021-04-15 19:14:45
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080701000051KK00489

檢視 Wayback Machine 備份