I have a query below that is returning individual sales records with amounts for each order placed for a specific product SKU. How would I go about summing the total amount? The column is "extprice" that I need to sum. Any help would be appreciated, thanks...
我在下面有一个查询,它返回单个销售记录,其中包含针对特定产品SKU的每个订单的金额。我如何总计总金额?该列是“extprice”,我需要总结。任何帮助将不胜感激,谢谢......
select partno4pt,orders.orderdate,orders.processdate,orderdetails.qty,orderdetails.extprice
from orderdetails
inner join orders
on orderdetails.order_id = orders.order_id
where orderdate > '2009.01.17 09:00:00'
and partnumber like '%m9150%'
and orders.processdate is not null
2 个解决方案
#1
0
You can just use the SUM aggregate function:
您可以使用SUM聚合函数:
select partno4pt,orders.orderdate,orders.processdate,orderdetails.qty,orderdetails.extprice,
SUM(orderdetails.extprice) AS sumprice from orderdetails
inner join orders on orderdetails.order_id = orders.order_id
where orderdate > '2009.01.17 09:00:00'
and partnumber like '%m9150%' and orders.processdate is not null
GROUP BY partno4pt,orders.orderdate,orders.processdate,orderdetails.qty,orderdetails.extprice
#2
4
I'm assuming a simple answer here due to it being a simple question:
由于这是一个简单的问题,我在这里假设一个简单的答案:
select SUM(orderdetails.extprice)
from orderdetails inner join orders on orderdetails.order_id = orders.order_id
where orderdate > '2009.01.17 09:00:00' and
partnumber like '%m9150%' and orders.processdate is not null
#1
0
You can just use the SUM aggregate function:
您可以使用SUM聚合函数:
select partno4pt,orders.orderdate,orders.processdate,orderdetails.qty,orderdetails.extprice,
SUM(orderdetails.extprice) AS sumprice from orderdetails
inner join orders on orderdetails.order_id = orders.order_id
where orderdate > '2009.01.17 09:00:00'
and partnumber like '%m9150%' and orders.processdate is not null
GROUP BY partno4pt,orders.orderdate,orders.processdate,orderdetails.qty,orderdetails.extprice
#2
4
I'm assuming a simple answer here due to it being a simple question:
由于这是一个简单的问题,我在这里假设一个简单的答案:
select SUM(orderdetails.extprice)
from orderdetails inner join orders on orderdetails.order_id = orders.order_id
where orderdate > '2009.01.17 09:00:00' and
partnumber like '%m9150%' and orders.processdate is not null