quisiera saber si existe la posibilidad de tener la sentencia "DROP TABLE TABLATEMPORAL" usando MySQL dentro de un trigger, ya que al intentar guardar el trigger con dicha sentencia me sale el siguiente error:
"There was an error while applying the SQL script to the database"
CREATE DEFINER=`root`@`localhost` TRIGGER `guardarResultadosFyS`
AFTER INSERT ON `mdl_feedback_completed` FOR EACH ROW
BEGIN
set @existe = (exists (select * from mdl_feedback_completed fc
join mdl_feedback_item fi where
label in ('Activo/Reflexivo' , 'Secuencial/Global' , 'Sensitivo/Intuitivo' , 'Visual/Verbal')
and fc.feedback = fi.feedback and fc.feedback = 3 limit 1));
if @existe !=0 then
CREATE TEMPORARY TABLE tmp_resultado AS
SELECT userid, username, fb.course as idcourse, c.feedback, concat(u.firstname, ' ', u.lastname ) as Nombre,
count(value) as valor, if(value = 1,
SUBSTRING_INDEX(SUBSTRING_INDEX(label, '/', 1), '/', -1),
SUBSTRING_INDEX(SUBSTRING_INDEX(label, '/', 2), '/', -1)) as dimension
FROM mdl_feedback_item d
JOIN mdl_feedback_value f
JOIN mdl_feedback_completed c
JOIN mdl_feedback fb
JOIN mdl_user u
WHERE c.userid = new.userid and c.feedback = new.feedback and c.id = f.completed and u.id = c.userid and c.feedback = fb.id and
label in ('Activo/Reflexivo' , 'Secuencial/Global' , 'Sensitivo/Intuitivo' , 'Visual/Verbal')
and d.id = f.item group by label, VALUE, nombre;
create temporary table tmp_resultadoPivote as
select
userid,
username,
idcourse,
Nombre ,
SUM(CASE WHEN dimension = 'Visual' THEN Valor ELSE 0 END) AS 'Visual' ,
SUM(CASE WHEN dimension = 'Verbal' THEN Valor ELSE 0 END) AS 'Verbal',
SUM(CASE WHEN dimension = 'Secuencial' THEN Valor ELSE 0 END) AS 'Secuencial' ,
SUM(CASE WHEN dimension = 'Global' THEN Valor ELSE 0 END) AS 'Global' ,
SUM(CASE WHEN dimension = 'Sensitivo' THEN Valor ELSE 0 END) AS 'Sensitivo' ,
SUM(CASE WHEN dimension = 'Intuitivo' THEN Valor ELSE 0 END) AS 'Intuitivo' ,
SUM(CASE WHEN dimension = 'Activo' THEN Valor ELSE 0 END ) AS 'Activo' ,
SUM(CASE WHEN dimension = 'Reflexivo' THEN Valor ELSE 0 END) AS 'Reflexivo'
from tmp_resultado;
create temporary table tmp_resultadoResta as
select userid, username, idcourse, Nombre,
(Visual - Verbal) as 'Visual_Verbal' , #visualverbal
(Secuencial - Global) as 'Secuencial_Global', #secuencialglobal
(activo - reflexivo) as 'Activo_Reflexivo' , #activoreflexivo
(sensitivo - Intuitivo) as 'Sensitivo_Intuitivo' #sensitivointuitivo
from tmp_resultadoPivote;
insert into mdl_feldersilverman
select idcourse, userid, username, nombre, now() as fecha, Visual_Verbal, Secuencial_Global,
Activo_Reflexivo, Sensitivo_Intuitivo from tmp_resultadoResta order by idcourse;
drop table tmp_resultado;
drop table tmp_resultadoPivote;
drop table tmp_resultadoResta;
end if;
END
Si elimino la sección donde estan los drop, me deja guardar el script sin problema pero al ejecutarlo una vez funciona bien, pero la segunda me sale el error de que existe la tabla "tmp_resultado"y eso por eso que busco eliminarlas