Mysql - Create temporary table according to dynamic SELECT

Asked

Viewed 14,029 times

1

Is there any way to create a temporary table according to a select with columns created dynamically, as shown in the examples below?

ex:

SELECT idCentroCusto, 'Dez/14', 'Jan/15', 'Fev/15', 'Mar/15', totalAnual

or

SELECT idCentroCusto, 'Dez/14', 'Jan/15', 'Fev/15', 'Mar/15', 'Abr/15', 'Mai/15', totalAnual

Since (as shown above) these Months/Year are dynamically created, according to the calendar parameter.

  • managed to create sql?

2 answers

3

See the documentation of CREATE TABLE, can be created through a consultation:

CREATE TEMPORARY TABLE tabela_temporaria SELECT idCentroCusto, 'Dez/14', 'Jan/15', 'Fev/15', 'Mar/15', totalAnual;

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.