Sql - 按总和更新组 [英] Sql - update group by sum
问题描述
嗨
我正在尝试使用另一个加入的表中的几个字段的总和来更新临时表,并且我收到以下错误消息:这段代码。
在预期条件的上下文中指定的非布尔类型的表达式
代码如下....
UPDATE #TempTable
SET TOTAL_AREA = AreaTotal,
TOTAL_AREA_VALUE = AreaTotalValue
FROM #TempTable INNER JOIN
(
SELECT SUM(tblWhereTotalsAre.AreaTotal)AS AreaTotal,
SUM(tblWhereTotalsAre.FinalValueTotal)as AreaTotalValue
FROM tblWhereTotalsAre INNER JOIN
tblHeader ON tblWhereTotalsAre.FK_ID = tblHeader.ID
WHERE tblWhereTotalsAre.ItemType ='建立'
GROUP BY tblWhereTotalsAre.FK_ID,tblHeader.Property,tblWhereTotalsAre.ItemType
)
知道我哪里出错或丢失。
我想从另一个有总和的表中的group子句更新临时表中的2个字段。 />
W帽子我试过:
我尝试了各种方法,但仍然收到错误消息。尝试而不是使用但仍然有故障。
Hi
I am trying to update a temp table with the sum of a couple of field from another table that is joined and I get the following error message with this piece of code.
"An expression of a non-Boolean type specified in a context where a condition is expected"
The code is as follows....
UPDATE #TempTable
SET TOTAL_AREA = AreaTotal,
TOTAL_AREA_VALUE = AreaTotalValue
FROM #TempTable INNER JOIN
(
SELECT SUM(tblWhereTotalsAre.AreaTotal) AS AreaTotal,
SUM(tblWhereTotalsAre.FinalValueTotal) as AreaTotalValue
FROM tblWhereTotalsAre INNER JOIN
tblHeader ON tblWhereTotalsAre.FK_ID = tblHeader.ID
WHERE tblWhereTotalsAre.ItemType = 'BUILDING'
GROUP BY tblWhereTotalsAre.FK_ID, tblHeader.Property, tblWhereTotalsAre.ItemType
)
Any idea where I am going wrong or missing.
I want to update 2 field in the temp table from a group clause in another table that has a sum.
What I have tried:
I have tried various ways but still get the error message. Tried instead of where used the having but still have a fault.
推荐答案
你没有为INNER JOIN指定ON子句,所以SQL不知道如何把两张桌子绑在一起。 (虽然愚蠢的消息)
You didn't specify the ON clause for the INNER JOIN, so SQL has no idea how to tie the two tables together. (Silly message though)
这篇关于Sql - 按总和更新组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!