MySQL - [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

 
Vista:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

Publicado por Dayana Pardo (2 intervenciones) el 14/12/2020 07:40:13
Saludos, podrían por favor ayudarme con este error


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
DECLARE @usu int
DECLARE @maxusu int
SET @usu = 939
SET @maxusu = (SELECT MAX(id) FROM mdl_user)
 
WHILE (@usu <= @maxusu)
begin
 
		SELECT t.fullname, t.firstname, t.username, max(t.sumtime) as tiempototal FROM (
		SELECT
			l.*,
			DATE_FORMAT(FROM_UNIXTIME(l.timecreated),'%d-%m-%Y') AS dTime,
			@prevtime := (
					SELECT timecreated FROM mdl_logusu
					WHERE userid = l.userid AND id < l.id ORDER BY id DESC LIMIT 1) AS prev_time,
			IF (l.timecreated - @prevtime < 7200, @delta := @delta + (l.timecreated-@prevtime),0)AS sumtime,
			l.timecreated-@prevtime AS delta,
			"User" AS TYPE
 
			FROM mdl_logusu AS l,
			(	SELECT @delta := 0) AS s_init
			# CHANGE UserID
			WHERE l.userid =@usu
		) as t
 
SET @usu = @usu +1
END

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DECLARE @usu int
DECLARE @maxusu int
SET @usu = 939
SET @maxusu = (SELECT MAX' at line 1
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 650
Plata
Ha mantenido su posición en MySQL (en relación al último mes)
Gráfica de MySQL

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

Publicado por joel (231 intervenciones) el 14/12/2020 10:35:37
Hola Dayana, prueba a poner el DELIMITER //... algo así:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
DELIMITER //
DECLARE @usu int
DECLARE @maxusu int
SET @usu = 939
SET @maxusu = (SELECT MAX(id) FROM mdl_user)
 
WHILE (@usu <= @maxusu)
begin
 
		SELECT t.fullname, t.firstname, t.username, max(t.sumtime) as tiempototal FROM (
		SELECT
			l.*,
			DATE_FORMAT(FROM_UNIXTIME(l.timecreated),'%d-%m-%Y') AS dTime,
			@prevtime := (
					SELECT timecreated FROM mdl_logusu
					WHERE userid = l.userid AND id < l.id ORDER BY id DESC LIMIT 1) AS prev_time,
			IF (l.timecreated - @prevtime < 7200, @delta := @delta + (l.timecreated-@prevtime),0)AS sumtime,
			l.timecreated-@prevtime AS delta,
			"User" AS TYPE
 
			FROM mdl_logusu AS l,
			(	SELECT @delta := 0) AS s_init
			# CHANGE UserID
			WHERE l.userid =@usu
		) as t
 
SET @usu = @usu +1
END //
DELIMITER ;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

Publicado por Dayana Pardo (2 intervenciones) el 14/12/2020 14:07:21
Hola, sigue apareciendo el mismo error

Sospecho que puede ser por la versión de la base de datos (10.1.48-MariaDB)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar