Sql server 在SQL Server中,两个选项只能选择一个
我已经很长时间没有使用SQL了,需要在几个小时内完成这项工作,请注意,我只需要在一个查询中完成他的工作,但我真的感到不知所措,当我尝试在一个查询中完成它时,这项工作不起作用 我无法将其添加到第一个查询Sql server 在SQL Server中,两个选项只能选择一个,sql-server,select,Sql Server,Select,我已经很长时间没有使用SQL了,需要在几个小时内完成这项工作,请注意,我只需要在一个查询中完成他的工作,但我真的感到不知所措,当我尝试在一个查询中完成它时,这项工作不起作用 我无法将其添加到第一个查询SUM(Venta.costAmount)中,因为Total_Region,似乎SUM出现了一些错误,我不知道为什么,当然,如果我删除SUM,会起作用 但是我需要字段的总数成本金额。请告知 SELECT Donde.region, Cuando.month, Venta.salesAmou
SUM(Venta.costAmount)中,因为Total_Region
,似乎SUM
出现了一些错误,我不知道为什么,当然,如果我删除SUM,会起作用
但是我需要字段的总数成本金额
。请告知
SELECT
Donde.region, Cuando.month, Venta.salesAmount, Que.brand
FROM
Donde
INNER JOIN
Venta ON Donde.id = Venta.storeId
INNER JOIN
Cuando ON Cuando.id = Venta.dateId
INNER JOIN
Que ON Que.id= Venta.productId
WHERE
Que.brand ='colhogar'
SELECT
Donde.region, SUM(Venta.costAmount) AS Total_Region
FROM
Donde
INNER JOIN
Venta ON Donde.id = Venta.storeId
INNER JOIN
Cuando ON Cuando.id = Venta.dateId
INNER JOIN
Que ON Que.id = Venta.productId
GROUP BY
ROLLUP (Donde.region)
试试这个答案
SELECT Donde.region, Cuando.month, Venta.salesAmount, Que.brand
,D.Total_Region CostAmount
FROM Donde INNER JOIN Venta ON Donde.id = Venta.storeId
INNER JOIN Cuando ON Cuando.id = Venta.dateId
INNER JOIN Que ON Que.id= Venta.productId
LEFT JOIN(
SELECT Donde.region, SUM(Venta.costAmount) AS Total_Region
FROM Donde INNER JOIN Venta ON Donde.id = Venta.storeId
INNER JOIN Cuando ON Cuando.id = Venta.dateId
INNER JOIN Que ON Que.id= Venta.productId
GROUP BY ROLLUP (Donde.region)
)D ON D.region=Donde.region
WHERE Que.brand ='colhogar'
如果有任何问题,请在评论中告诉我。哪个sql数据库?