【发布时间】:2017-03-13 04:59:00
【问题描述】:
我对 sql 和 Stack Overflow 非常陌生。我希望有人可以帮助我进行此查询。我的查询应该显示销售额超过 200,000 美元的类别的总销售额和总销售额。我已经在这个查询上工作了一个小时,而且我束手无策,感谢您的帮助!
select distinct c.categoryname,
sum(p.unitprice * od.Quantity) as 'Sales'
from Categories c
inner join Products p
on c.CategoryID = p.CategoryID
inner join OrderDetails od
on p.ProductID = od.ProductID
where p.unitprice < 200000
group by c.categoryname
我希望我至少在正确的轨道上,感谢您的帮助!
【问题讨论】:
-
您正在过滤那些单价小于 20000的产品,这是为什么呢?
-
可能是
sales > 200000而不是单价 -
@prashanth - 我尝试了您的建议,但收到此错误:“将 varchar 值 'sales' 转换为数据类型 int 时转换失败。”无论如何感谢您的尝试!
-
我的错......它比较了字符串
"slaes"而不是sum(p.unitprice * od.Quantity)!因此,您可以使用sum(p.unitprice * od.Quantity) > 200000及其>来代替 p.unitprice :)
标签: mysql sql-server database