110,534
社区成员
发帖
与我相关
我的任务
分享
DECLARE @FilterType NVARCHAR
SET @FilterType = '1'
;WITH t AS (
SELECT
STDEV(hitrate) AS hitrate_STDEV
,AVG(hitrate)AS hitrate_AVG
,STDEV(profit) AS profit_STDEV
,AVG(profit)AS profit_AVG
,STDEV(profitbillity) AS profitbillity_STDEV
,AVG(profitbillity)AS profitbillity_AVG
,STDEV(tipscount) AS tipscount_STDEV
,AVG(tipscount)AS tipscount_AVG
,STDEV(redtimescount) AS redtimescount_STDEV
,AVG(redtimescount)AS redtimescount_AVG
FROM TipsterFilterObject
WHERE FilterType = @FilterType
)
UPDATE TipsterFilterObject
SET CalculatePoints = IIF(t.hitrate_STDEV= 0,0, 0.3 * 1000 * ( hitrate -t.hitrate_AVG) / t.hitrate_STDEV)
+ IIF(t.profit_STDEV= 0,0, 0.3 * 1000 * ( profit -t.profit_AVG) / t.profit_STDEV)
+ IIF(t.profitbillity_STDEV= 0,0, 0.1 * 1000 * ( profitbillity - t.profitbillity_AVG) / t.profitbillity_STDEV)
+ IIF(t.tipscount_STDEV= 0,0, 0.1 * 1000 * ( tipscount -t.tipscount_AVG) / t.tipscount_STDEV)
+ IIF(t.redtimescount_STDEV= 0,0, 0.2 * 1000 * ( redtimescount -t.redtimescount_AVG) / t.redtimescount_STDEV)
FROM t
WHERE FilterType= @FilterType
楼主换这个试试[/quote]
多谢,后来改了with as。但是之前加了几个索引之后,性能问题解决了。所以也不知道到底是with 起作用了,还是索引起作用了。[/quote]
可以删除索引, 再试下效果。
没事就结贴吧。DECLARE @FilterType NVARCHAR
SET @FilterType = '1'
;WITH t AS (
SELECT
STDEV(hitrate) AS hitrate_STDEV
,AVG(hitrate)AS hitrate_AVG
,STDEV(profit) AS profit_STDEV
,AVG(profit)AS profit_AVG
,STDEV(profitbillity) AS profitbillity_STDEV
,AVG(profitbillity)AS profitbillity_AVG
,STDEV(tipscount) AS tipscount_STDEV
,AVG(tipscount)AS tipscount_AVG
,STDEV(redtimescount) AS redtimescount_STDEV
,AVG(redtimescount)AS redtimescount_AVG
FROM TipsterFilterObject
WHERE FilterType = @FilterType
)
UPDATE TipsterFilterObject
SET CalculatePoints = IIF(t.hitrate_STDEV= 0,0, 0.3 * 1000 * ( hitrate -t.hitrate_AVG) / t.hitrate_STDEV)
+ IIF(t.profit_STDEV= 0,0, 0.3 * 1000 * ( profit -t.profit_AVG) / t.profit_STDEV)
+ IIF(t.profitbillity_STDEV= 0,0, 0.1 * 1000 * ( profitbillity - t.profitbillity_AVG) / t.profitbillity_STDEV)
+ IIF(t.tipscount_STDEV= 0,0, 0.1 * 1000 * ( tipscount -t.tipscount_AVG) / t.tipscount_STDEV)
+ IIF(t.redtimescount_STDEV= 0,0, 0.2 * 1000 * ( redtimescount -t.redtimescount_AVG) / t.redtimescount_STDEV)
FROM t
WHERE FilterType= @FilterType
楼主换这个试试[/quote]
多谢,后来改了with as。但是之前加了几个索引之后,性能问题解决了。所以也不知道到底是with 起作用了,还是索引起作用了。DECLARE @FilterType NVARCHAR
SET @FilterType = '1'
;WITH t AS (
SELECT
STDEV(hitrate) AS hitrate_STDEV
,AVG(hitrate)AS hitrate_AVG
,STDEV(profit) AS profit_STDEV
,AVG(profit)AS profit_AVG
,STDEV(profitbillity) AS profitbillity_STDEV
,AVG(profitbillity)AS profitbillity_AVG
,STDEV(tipscount) AS tipscount_STDEV
,AVG(tipscount)AS tipscount_AVG
,STDEV(redtimescount) AS redtimescount_STDEV
,AVG(redtimescount)AS redtimescount_AVG
FROM TipsterFilterObject
WHERE FilterType = @FilterType
)
UPDATE TipsterFilterObject
SET CalculatePoints = IIF(t.hitrate_STDEV= 0,0, 0.3 * 1000 * ( hitrate -t.hitrate_AVG) / t.hitrate_STDEV)
+ IIF(t.profit_STDEV= 0,0, 0.3 * 1000 * ( profit -t.profit_AVG) / t.profit_STDEV)
+ IIF(t.profitbillity_STDEV= 0,0, 0.1 * 1000 * ( profitbillity - t.profitbillity_AVG) / t.profitbillity_STDEV)
+ IIF(t.tipscount_STDEV= 0,0, 0.1 * 1000 * ( tipscount -t.tipscount_AVG) / t.tipscount_STDEV)
+ IIF(t.redtimescount_STDEV= 0,0, 0.2 * 1000 * ( redtimescount -t.redtimescount_AVG) / t.redtimescount_STDEV)
FROM t
WHERE FilterType= @FilterType
楼主换这个试试
declare @FilterType nvarchar
set @FilterType='1'
update TipsterFilterObject set CalculatePoints=
iif((select STDEV(hitrate) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType )=0,0, 0.3*1000*(hitrate-(select AVG(hitrate) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))/(select STDEV(hitrate) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))
+iif((select STDEV(profit) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType)=0,0, 0.3*1000*(profit-(select AVG(profit) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))/(select STDEV(profit) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))
+iif((select STDEV(profitbillity) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType)=0,0, 0.1*1000*(profitbillity-(select AVG(profitbillity) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))/(select STDEV(profitbillity) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))
+iif((select STDEV(tipscount) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType)=0,0, 0.1*1000*(tipscount-(select AVG(tipscount) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))/(select STDEV(tipscount) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))
+iif((select STDEV(redtimescount) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType)=0,0, 0.2*1000*(redtimescount-(select AVG(redtimescount) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType))/(select STDEV(redtimescount) from TipsterFilterObject with(NOLOCK) where FilterType=@FilterType)) where FilterType=@FilterType
脚本如上,NOLOCK是后加的,然并卵。