mysql - Create table from a previous prepared statemt -
hi i've got part of more complex query:
prepare stmt @sql; execute stmt; deallocate prepare stmt;
rather executing stmt want create table result of execute.
create table select * (execute stmt)
gives me error
edit: here's entire stuff:
use catdatabase; set session group_concat_max_len = 1000000; set @sql = null; select group_concat(distinct concat('sum(case when columna = "' ,columna, '"then 1 else 0 end) "' ,columna, '"')) @sql tableb; set @sql = concat('select columnb, count(*) total, ', @sql, ' tablea inner join tableb on tablea.columnc = tableb.columne tablea.columnd <> "catpoop" group columnb'); prepare stmt @sql; execute stmt; deallocate prepare stmt;
as can see want pivot data , wants save temporary table. have updated query, please check out this:
use catdatabase; set session group_concat_max_len = 1000000; set @sql = null; select group_concat(distinct concat('sum(case when columna = "' ,columna, '"then 1 else 0 end) "' ,columna, '"')) @sql tableb; set @sql = concat('create temporary table temp select columnb, count(*) total, ', @sql, ' tablea inner join tableb on tablea.columnc = tableb.columne tablea.columnd <> "catpoop" group columnb'); prepare stmt @sql; execute stmt; deallocate prepare stmt;
if error in let me know.
Comments
Post a Comment