⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4_5(2).sql

📁 to become acquainted with a concept &#171 cursor&#187 language of SQL, by the types of cursors, to
💻 SQL
字号:
if (cursor_status('global', 'cursor1') <> -3) 
	deallocate global cursor1

declare cursor1 cursor
global
scroll
static
for select  grouppa.id_group
  from Grouppa 
  inner JOIN Student 
  ON grouppa.id_group=Student.id_group
  inner join form_edu
  on form_edu.id_form=student.id_form
  where form_edu.form_name='Vechernee' or form_edu.form_name= 'Zaochne'
	ORDER BY 	id_group	




open cursor1
declare 
@kol int,
@id1 int,
@id2 int,
@idmax int,
@max int
	set @kol=0
	set @id1=0
	set @id2=0
    set @idmax=0
	set @max=0
		
while(1=1)
begin

	fetch next from cursor1 into @id1
	--SELECT @ID1
			if(@@fetch_status=-1)
				break;
			if(@@fetch_status<>-2)
			begin
				if (@id1=@id2) 		set @kol=@kol+1
			    if (@kol>@max) 
				begin
				  set @max=@kol
				  set @idmax=@id2	
				end
				if (@id1<>@id2) set @kol=0
				set @id2=@id1
			end
		
end

close cursor1
deallocate global cursor1

select @idmax as idmax, @max as kol

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -