我有这样一个SQL语句:
Insert into @Matches(RowId, PercentMatch) select distinct t.[Row],
cast(Max(Counts) as float)/(Abs(Max(Counts) - case when Max(VarLength) >= @tempint then Max(VarLength) else @tempint end) + Max(Counts))* 100
As MatchingPercent from @Temp t Group by [Row] order by MatchingPercent desc我拥有的下一个sql语句是:
Update @Matches set Percentage = PercentMatch * @constantVal我想强调指出,PercentMatch列在上面的Insert Insert select语句中是“计算”的。
我想做什么:如何在一条语句中合并它?
为什么我需要这个:
它位于由异步执行的20-30个存储过程(使用Service )执行的过程中。
发布于 2015-03-30 14:02:29
您可以将SELECT放在子查询中,并通过在外部查询中执行乘法,在INSERT语句中插入Percentage值:
Insert into @Matches(RowId, PercentMatch, Percentage)
select tRow, MatchingPercent, MatchingPercent * @constantVal
from (
select distinct t.[Row] as tRow,
cast(Max(Counts) as float) / (Abs(Max(Counts)
-
case
when Max(VarLength) >= @tempint then Max(VarLength)
else @tempint
end) + Max(Counts))* 100 As MatchingPercent
from @Temp t
Group by [Row] ) s我还认为order by子句在INSERT INTO SELECT语句中没有多大用处。
https://stackoverflow.com/questions/29348057
复制相似问题