[英]SQL sum of merchandise daily and weekly
I'm trying to get the total price of merchandise sold at a game for a school project.我正在尝试获取学校项目游戏中所售商品的总价格。 I returned the values of each individual type with this code:
我使用以下代码返回了每种类型的值:
Select GameDate as game, Format(sum(quantity * price),'c') as price from CityBloomers1.dbo.SalesTransaction
join CityBloomers1.dbo.merchandise on CityBloomers1.dbo.SalesTransaction.Merchandise=CityBloomers1.dbo.merchandise.merchandise
group by gameDate, Quantity
I need code to get the total price for all merchandise sold at a game, and the sum of that number in one column.我需要代码来获取在游戏中销售的所有商品的总价格,以及一列中该数字的总和。 Example(I cant post images, so this is the best way I can interpret what I want to get)
示例(我不能发布图片,所以这是我可以解释我想要得到的最好的方式)
Merchandise|Price
(GameDate1)|sum sold that day
(GameDate2)|sum sold that day
Total |total sold both days
you can use您可以使用
you can use rollup
:你可以使用
rollup
:
Select
GameDate as game,
Format(sum(quantity * price), 'c') as price
from
CityBloomers1.dbo.SalesTransaction
join CityBloomers1.dbo.merchandise on CityBloomers1.dbo.SalesTransaction.Merchandise = CityBloomers1.dbo.merchandise.merchandise
group by rollup(gameDate,Quantity)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.