Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

prezadoline

Converter para View

Recommended Posts

Olá pessoal.

Estou tentando criar essa view mas não está dando certo. O Mysql não aceita um select dentro do outro.

CREATE
DEFINER = 'meu_nome'@'localhost'
VIEW meu_banco.vw_grid_carne_lanc
AS
SELECT
  'id_lancamento_financeiro' AS 'id_lancamento_financeiro',
  'valor_lancamento' AS 'valor_lancamento',
  'data_lancamento' AS 'data_lancamento',
  'mes_lancamento' AS 'mes_lancamento',
  'mes' AS 'mes',
  'dia' AS 'dia',
  'ano' AS 'ano'
FROM (
	SELECT 
	      day (data_lancamento) AS dia,
	      year(data_lancamento) AS ano,    
	      (CASE monthname(data_lancamento) 
	         when 'January'   then 'Janeiro'
	         when 'February'  then 'Fevereiro'
	         when 'March' 	  then 'Março'
	         when 'April'     then 'Abril'
	         when 'May'       then 'Maio'
	         when 'June'      then 'Junho'
	         when 'July'      then 'Julho'
	         when 'August'    then 'Agosto'
	         when 'September' then 'Setembro'
	         when 'October'   then 'Outubro'
	         when 'November'  then 'Novembro'
	         when 'December'  then 'Dezembro'
	         END
	       ) AS mes,         
	       data_lancamento,
	       mes_lancamento,
	       valor_lancamento         
	FROM tb_lancamento_financeiro
	WHERE not (data_lancamento is null)
    ) as tb_lancamento_financeiro
GROUP BY mes_lancamento
ORDER BY mes_lancamento;

Será que alguém poderia me dar uma dica.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pq precisa da tabela virtual ? Não entendi o motivo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tenho que ter essa saída no Mysql:

16-05-2015%2022-38-37.jpg

Minha base de dados está assim:

16-05-2015%2022-41-34.jpg

Sei que estou repetindo a informação dia;mês;ano mas por enquanto é só teste, não vai ser definitivo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você não parece pre isar do subselect, todas as colunas estão no subselect.

Compartilhar este post


Link para o post
Compartilhar em outros sites


CREATE OR REPLACE VIEW meu_banco.vw_grid_carne_lanc

AS

SELECT

day (data_lancamento) AS dia,

year(data_lancamento) AS ano,

(CASE monthname(data_lancamento)

when 'January' then 'Janeiro'

when 'February' then 'Fevereiro'

when 'March' then 'Março'

when 'April' then 'Abril'

when 'May' then 'Maio'

when 'June' then 'Junho'

when 'July' then 'Julho'

when 'August' then 'Agosto'

when 'September' then 'Setembro'

when 'October' then 'Outubro'

when 'November' then 'Novembro'

when 'December' then 'Dezembro'

END

) AS mes,

data_lancamento,

mes_lancamento,

valor_lancamento

FROM tb_lancamento_financeiro

WHERE not (data_lancamento is null)

)

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.