SQL 更新查询
我有一个主表(例如主表)和另一个临时表(例如副本)。 我想做的是主表中每个存储过程的平均值和标准差(其中有一堆具有不同版本号作为后缀,并且它们都必须被相同地对待),并更新临时表,其中每个存储过程的平均值和标准差天。 以下是我的不起作用的代码......
UPDATE @CopyOfMainTable AS copy
SET copy.overall_count_average = AVG(main.overall_count),
copy.overall_count_stddev=StDev(main.overall_count),
copy.redundancy_count_average =AVG (main.redundancy_count),
copy.redundancy_count_stddev=StDev(main.redundancy_count),
copy.not_completed_count_average AVG(main.not_completed_count),
copy.not_completed_count_stddev=StDev(main.not_completed_count),
copy.session_count_average= AVG(main.session_count),
copy.session_count_stddev=StDev(main.session_count),
copy.per_session_count_average_average = AVG (main.per_session_count_avg),
copy.per_session_count_average_stddev = StDev(main.per_session_count_avg),
copy.per_session_count_max_average = AVG(main.per_session_count_max),
copy.per_session_count_max_stddev= StDev(main.per_session_count_max),
copy.per_session_count_stddev_average=AVG(main.per_session_count_stddev),
copy.per_session_count_stddev_stddev=StDev(main.per_session_count_stddev),
copy.run_time_average_average = AVG(main.run_time_avg),
copy.run_time_average_stddev = StDev(main.run_time_avg),
copy.run_time_max_average =AVG(main.run_time_max),
copy.run_time_max_stddev= StDev(main.run_time_max),
copy.run_time_stddev_average=AVG(main.run_time_stddev),
copy.run_time_stddev_stddev=StDev(main.run_time_stddev),
copy.run_time_core_hours_avg_average=Avg(main.run_time_core_hours_avg),
copy.run_time_core_hours_avg_stddev=StDev(main.run_time_core_hours_avg),
copy.run_time_core_hours_max_average=Avg(main.run_time_core_hours_max),
copy.run_time_core_hours_max_stddev=StDev(main.run_time_core_hours_max),
copy.run_time_core_hours_stddev_average=Avg(main.run_time_core_hours_stddev),
copy.run_time_core_hours_stddev_stddev=StDev(main.run_time_core_hours_stddev),
copy.run_time_peak_hours_avg_average=Avg(main.run_time_peak_hours_avg),
copy.run_time_peak_hours_avg_stddev=StDev(main.run_time_peak_hours_avg),
copy.run_time_peak_hours_max_average=Avg(main.run_time_peak_hours_max),
copy.run_time_peak_hours_max_stddev=StDev(main.run_time_peak_hours_max),
copy.run_time_peak_hours_stddev_average=Avg(main.run_time_peak_hours_stddev),
copy.run_time_peak_hours_stddev_stddev=StDev(main.run_time_peak_hours_stddev),
copy.run_time_min_average=Avg(main.run_time_min),
copy.run_time_min_stddev=StDev(main.run_time_min),
copy.run_time_core_hours_min_average=Avg(main.run_time_core_hours_min),
copy.run_time_core_hours_min_stddev=StDev(main.run_time_core_hours_min),
copy.run_time_peak_hours_min_average=Avg(main.run_time_peak_hours_min),
copy.run_time_peak_hours_min_stddev=StDev(main.run_time_peak_hours_min)
FROM dbo.database_call_tracking as main
WHERE(main.date < @latestDay_ToBeConsidered_Forthreshhold) AND (main.day_of_week BETWEEN 2 AND 6) AND (main.database_call like '%'+copy.database_call+'%')--AND (main.database_call LIKE '%[_]v[1-9]%'
Group by database_call
这根本不起作用。 有人可以帮忙吗? 或者可能会建议什么?
I have One main table( Say main) and another Temp Table( say copy). What I am trying to do is averages and Standard Deviation of each Stored proc( there are bunch of them with different version number as suffix and they all has to be treated same) from main table and update Temp table with averages and standard deviation for each day. Following is my NOT working Code....
UPDATE @CopyOfMainTable AS copy
SET copy.overall_count_average = AVG(main.overall_count),
copy.overall_count_stddev=StDev(main.overall_count),
copy.redundancy_count_average =AVG (main.redundancy_count),
copy.redundancy_count_stddev=StDev(main.redundancy_count),
copy.not_completed_count_average AVG(main.not_completed_count),
copy.not_completed_count_stddev=StDev(main.not_completed_count),
copy.session_count_average= AVG(main.session_count),
copy.session_count_stddev=StDev(main.session_count),
copy.per_session_count_average_average = AVG (main.per_session_count_avg),
copy.per_session_count_average_stddev = StDev(main.per_session_count_avg),
copy.per_session_count_max_average = AVG(main.per_session_count_max),
copy.per_session_count_max_stddev= StDev(main.per_session_count_max),
copy.per_session_count_stddev_average=AVG(main.per_session_count_stddev),
copy.per_session_count_stddev_stddev=StDev(main.per_session_count_stddev),
copy.run_time_average_average = AVG(main.run_time_avg),
copy.run_time_average_stddev = StDev(main.run_time_avg),
copy.run_time_max_average =AVG(main.run_time_max),
copy.run_time_max_stddev= StDev(main.run_time_max),
copy.run_time_stddev_average=AVG(main.run_time_stddev),
copy.run_time_stddev_stddev=StDev(main.run_time_stddev),
copy.run_time_core_hours_avg_average=Avg(main.run_time_core_hours_avg),
copy.run_time_core_hours_avg_stddev=StDev(main.run_time_core_hours_avg),
copy.run_time_core_hours_max_average=Avg(main.run_time_core_hours_max),
copy.run_time_core_hours_max_stddev=StDev(main.run_time_core_hours_max),
copy.run_time_core_hours_stddev_average=Avg(main.run_time_core_hours_stddev),
copy.run_time_core_hours_stddev_stddev=StDev(main.run_time_core_hours_stddev),
copy.run_time_peak_hours_avg_average=Avg(main.run_time_peak_hours_avg),
copy.run_time_peak_hours_avg_stddev=StDev(main.run_time_peak_hours_avg),
copy.run_time_peak_hours_max_average=Avg(main.run_time_peak_hours_max),
copy.run_time_peak_hours_max_stddev=StDev(main.run_time_peak_hours_max),
copy.run_time_peak_hours_stddev_average=Avg(main.run_time_peak_hours_stddev),
copy.run_time_peak_hours_stddev_stddev=StDev(main.run_time_peak_hours_stddev),
copy.run_time_min_average=Avg(main.run_time_min),
copy.run_time_min_stddev=StDev(main.run_time_min),
copy.run_time_core_hours_min_average=Avg(main.run_time_core_hours_min),
copy.run_time_core_hours_min_stddev=StDev(main.run_time_core_hours_min),
copy.run_time_peak_hours_min_average=Avg(main.run_time_peak_hours_min),
copy.run_time_peak_hours_min_stddev=StDev(main.run_time_peak_hours_min)
FROM dbo.database_call_tracking as main
WHERE(main.date < @latestDay_ToBeConsidered_Forthreshhold) AND (main.day_of_week BETWEEN 2 AND 6) AND (main.database_call like '%'+copy.database_call+'%')--AND (main.database_call LIKE '%[_]v[1-9]%'
Group by database_call
This is Not working at all. Can anyone Help? or may be suggest something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您需要针对此场景使用子查询; 这是一个简化示例:
Typically, you need a sub-query for this scenario; here's a simplified example: