
用SQL统计每种商品的销售总额
统计2007年每种商品的销售总额,按销售总额降序显示结果Products表--ProductIDProductNameSupplierIDCategoryIDQuanti...
统计2007年每种商品的销售总额,按销售总额降序显示结果
Products表--ProductID ProductName SupplierID CategoryID QuantityPerUnit UnitPrice UnitsInStock
Orders表--OrderID CustomerID EmployeeID OrderDate
OrderDetails表--OrderID ProductID UnitPrice Quantity
select ProductName,sum(UnitPrice*Quantity)--这个销售总额不知怎写
from Products join OrderDetails
on Products.ProductID=OrderDetails.ProductID join Orders
on OrderDetails.OrderID=Orders.OrderID
where OrderDate>='2007-1-1'and OrderDate < '2007-12-1'
order by sum desc 展开
Products表--ProductID ProductName SupplierID CategoryID QuantityPerUnit UnitPrice UnitsInStock
Orders表--OrderID CustomerID EmployeeID OrderDate
OrderDetails表--OrderID ProductID UnitPrice Quantity
select ProductName,sum(UnitPrice*Quantity)--这个销售总额不知怎写
from Products join OrderDetails
on Products.ProductID=OrderDetails.ProductID join Orders
on OrderDetails.OrderID=Orders.OrderID
where OrderDate>='2007-1-1'and OrderDate < '2007-12-1'
order by sum desc 展开
展开全部
你写的基本差不多了,不过表连接的顺序最好按用到的前后来连接,不然影响效率
select P.ProductName, sum(OD.UnitPrice*OD.Quantity) total_sales
from Orders O
join OrderDetails OD on OD.OrderID=O.OrderID
join Products P on P.ProductID=OD.ProductID
where OD.OrderDate>='2007-1-1'and OD.OrderDate < '2007-12-1'
group by P.ProductName
order by total_sales desc
select P.ProductName, sum(OD.UnitPrice*OD.Quantity) total_sales
from Orders O
join OrderDetails OD on OD.OrderID=O.OrderID
join Products P on P.ProductID=OD.ProductID
where OD.OrderDate>='2007-1-1'and OD.OrderDate < '2007-12-1'
group by P.ProductName
order by total_sales desc
展开全部
select ProductName,sum(UnitPrice*Quantity)--这个销售总额不知怎写
from Products join OrderDetails
on Products.ProductID=OrderDetails.ProductID join Orders
on OrderDetails.OrderID=Orders.OrderID
where OrderDate>='2007-1-1'and OrderDate < '2007-12-1'
group by Products.ProductID,Products.ProductName
from Products join OrderDetails
on Products.ProductID=OrderDetails.ProductID join Orders
on OrderDetails.OrderID=Orders.OrderID
where OrderDate>='2007-1-1'and OrderDate < '2007-12-1'
group by Products.ProductID,Products.ProductName
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a.productname,sum(uitprict*quantity)
from products a,orders b,orderdetails c
where a.productid=c.productid(+)
and b.orderId=c.orderid
and b.orderdate between to_date('20170101','yyyy-mm-dd') and to_date('20171231','yyyy-mm-dd')
group by a.productname
order by sum(uitprict*quantity) desc;
from products a,orders b,orderdetails c
where a.productid=c.productid(+)
and b.orderId=c.orderid
and b.orderdate between to_date('20170101','yyyy-mm-dd') and to_date('20171231','yyyy-mm-dd')
group by a.productname
order by sum(uitprict*quantity) desc;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select ProductName,sum(UnitPrice*Quantity)
from Products a
join OrderDetails b
on a.ProductID=b.ProductID
join Orders c
on b.OrderID=c.OrderID
where c.OrderDate between'2007-01-01'and'2007-12-01'
group by ProductName
order by sum(UnitPrice*Quantity) desc
from Products a
join OrderDetails b
on a.ProductID=b.ProductID
join Orders c
on b.OrderID=c.OrderID
where c.OrderDate between'2007-01-01'and'2007-12-01'
group by ProductName
order by sum(UnitPrice*Quantity) desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select ProductName,sum(UnitPrice*Quantity) as SumPrice
from Products join OrderDetails
on Products.ProductID=OrderDetails.ProductID join Orders
on OrderDetails.OrderID=Orders.OrderID
where OrderDate>='2007-1-1'and OrderDate < '2007-12-1' group by ProductName order by sum desc
from Products join OrderDetails
on Products.ProductID=OrderDetails.ProductID join Orders
on OrderDetails.OrderID=Orders.OrderID
where OrderDate>='2007-1-1'and OrderDate < '2007-12-1' group by ProductName order by sum desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询