sql 删除动态波形中的重复评估

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 删除动态波形中的重复评估相关的知识,希望对你有一定的参考价值。

DECLARE @tbl TABLE (
	Id INT identity(1, 1)
	,uccps INT
	)

INSERT INTO @tbl (uccps)
SELECT UserCenterXCenterPguSkillId
FROM Assessment a
WHERE a.AssessmentName = 'A&LR'
	AND a.IsActive = 1
GROUP BY UserCenterXCenterPguSkillId
HAVING COUNT(assessmentId) > 1

SELECT *
FROM @tbl

DECLARE @i INT = 1
DECLARE @rCount INT = 0

SELECT @rCount = COUNT(1)
FROM @tbl

DECLARE @Luccps INT = 0
DECLARE @assessmentId INT

WHILE (@i <= @rCount)
BEGIN
	SELECT @Luccps = uccps
	FROM @tbl
	WHERE Id = @i;

	SELECT TOP 1 @assessmentId = AssessmentId
	FROM Assessment
	WHERE UserCenterXCenterPguSkillId = @Luccps
		AND AssessmentStatusId IN (1, 3)

	IF (@assessmentId > 0)
	BEGIN
		UPDATE Assessment
		SET IsActive = 0
		WHERE AssessmentId = @assessmentId
	END

	SET @assessmentId = 0
	SET @i = @i + 1;
END

以上是关于sql 删除动态波形中的重复评估的主要内容,如果未能解决你的问题,请参考以下文章

为啥没有在动态 SQL 中评估数学条件?

评估真实值[重复]

case-when oracle sql的动态评估

在表值函数中使用 SQL Server 2008 中的动态 SQL 语句 [重复]

删除sql查询中的重复行[重复]

是否可以用波形结构屏蔽 div