Is it possible to reference an alias in Mysql and use its field value?

Asked

Viewed 13 times

0

I have the following situation: An electronic point in mysql and working on a query that makes several calculations with dates and times.

select
nome_colaborador,
date_format(data_registro, "%d %M %Y") as Dia, 
time_format(hora_entrada, "%Hh %i")  as Entrada, 
time_format(hora_saida, "%Hh %i")  as Saída,
time_format(timediff(hora_saida, hora_entrada), "%Hh %i") as 'Tempo de Presença'
from ponto_eletronico
join colaborador on colaborador_matricula_colaborador = matricula_colaborador;
;

The question is: I will add a new field that is "Hours balance", it is nothing more than subtracting the total of hours that the person has to fulfill on that day, with how much she fulfilled on that day (the 'Presence time') so I want to know if there’s a way to reference this alias instead of having to include the whole calculation again.

  • "if there is a way to make a reference to this alias instead of having to include the whole calculation again" I read it was not clear, can put as it would be the query to illustrate better?

  • I wanted the next field to be calculated like this: timediff('Presence Time','<Journey>')

  • and "Jornada" is the right alias? if this is not to be used in the same query :(

  • Fellow, as I explained, journey no matter for doubt, it will be a field recorded in the table.

  • What I want to know is if the part of 'Presence time', alias of a field generated from calculations made with the hora_input and hora_output data, can be used to calculate another field

No answers

Browser other questions tagged

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