请教一个sql语句,不知道怎么写?
发布网友
发布时间:2023-10-19 20:23
我来回答
共4个回答
热心网友
时间:2024-12-12 22:42
DECLARE @Name VARCHAR(50) ,
@Date DATE ,
@preName VARCHAR(50) ,
@preDate DATE ,
@count INT,
@reDay BIT
DECLARE @itemCur CURSOR
SET
@itemCur = CURSOR FOR
SELECT name,date FROM test
ORDER BY name,date
SET @count = 1
SET @reDay=0
OPEN @itemCur
FETCH NEXT FROM @itemCur INTO @Name, @Date
SET @preName = @Name
SET @preDate = @Date
WHILE @@FETCH_STATUS = 0
BEGIN
IF ( @preName = @Name
AND DATEDIFF(DAY, @preDate, @date) BETWEEN -1 AND 1
)
BEGIN
SET @count = @count + 1
IF(DATEDIFF(DAY, @preDate, @date)=0)
SET @reDay=1
END
ELSE
BEGIN
SET @count = 1
SET @reDay=0
END
SET @preName = @Name
SET @preDate = @Date
FETCH NEXT FROM @itemCur INTO @Name, @Date
IF ( @count = 4 AND @reDay=1)
PRINT ( @Name )
END
CLOSE @itemCur
DEALLOCATE @itemCur
热心网友
时间:2024-12-12 22:42
坐等答案!!!!!!!1
热心网友
时间:2024-12-12 22:43
只用SQL 是不可能实现的,帮不到你了
热心网友
时间:2024-12-12 22:44
可以写存储过程吗?