Duvida sobre query mysql

13/01/2017

0

Eu fiz esse select e eu preciso que me retorne apenas uma única linha com as informações, e preciso que me de o tempo do atendimento até o fechamento (em minutos) ENTRE O CAMPOS atendimento fechamento <- (data e hora)

o retorno do select:

Retorno do Select no Banco



SELECT
SECTOR,
TICKET,
ASSUNTO,
MAX(ATENDIMENTO) ATENDIMENTO,
MAX(FECHAMENTO) FECHAMENTO

from (

select concat(customer_user.first_name, ' ', customer_user.last_name) SECTOR,
ticket.tn TICKET,
ticket.title ASSUNTO,
NULL ATENDIMENTO,
NULL FECHAMENTO


from ticket, customer_user, ticket_history
where ticket.customer_user_id = customer_user.login
and ticket.id = ticket_history.ticket_id
and ticket.tn = 2017011349000468) tn


UNION ALL

select concat(customer_user.first_name, ' ', customer_user.last_name) SECTOR,
ticket.tn TICKET,
ticket.title ASSUNTO,
MAX(ticket_history.create_time) ATENDIMENTO,
NULL FECHAMENTO

from ticket, customer_user, ticket_history
where ticket.customer_user_id = customer_user.login
and ticket.id = ticket_history.ticket_id
and ticket.tn = 2017011349000468
and ticket_history.history_type_id = 27
and ticket_history.state_id = 10



UNION ALL

select concat(customer_user.first_name, ' ', customer_user.last_name) SECTOR,
ticket.tn TICKET,
ticket.title ASSUNTO,
NULL ATENDIMENTO,
MAX(ticket_history.create_time) FECHAMENTO

from ticket, customer_user, ticket_history
where ticket.customer_user_id = customer_user.login
and ticket.id = ticket_history.ticket_id
and ticket.tn = 2017011349000468
and ticket_history.history_type_id = 27
and ticket_history.state_id = 2



group by
SECTOR,
TICKET,
ASSUNTO
Oseias Neri

Oseias Neri

Responder

Posts

13/01/2017

Oseias Neri

A QUERY:



SELECT
SECTOR,
TICKET,
ASSUNTO,
MAX(ATENDIMENTO) ATENDIMENTO,
MAX(FECHAMENTO) FECHAMENTO

from (

select concat(customer_user.first_name, ' ', customer_user.last_name) SECTOR,
ticket.tn TICKET,
ticket.title ASSUNTO,
NULL ATENDIMENTO,
NULL FECHAMENTO

from ticket, customer_user, ticket_history
where ticket.customer_user_id = customer_user.login
and ticket.id = ticket_history.ticket_id
and ticket.tn = 2017011349000468) tn


UNION ALL

select concat(customer_user.first_name, ' ', customer_user.last_name) SECTOR,
ticket.tn TICKET,
ticket.title ASSUNTO,
MAX(ticket_history.create_time) ATENDIMENTO,
NULL FECHAMENTO

from ticket, customer_user, ticket_history
where ticket.customer_user_id = customer_user.login
and ticket.id = ticket_history.ticket_id
and ticket.tn = 2017011349000468
and ticket_history.history_type_id = 27
and ticket_history.state_id = 10



UNION ALL

select concat(customer_user.first_name, ' ', customer_user.last_name) SECTOR,
ticket.tn TICKET,
ticket.title ASSUNTO,
NULL ATENDIMENTO,
MAX(ticket_history.create_time) FECHAMENTO

from ticket, customer_user, ticket_history
where ticket.customer_user_id = customer_user.login
and ticket.id = ticket_history.ticket_id
and ticket.tn = 2017011349000468
and ticket_history.history_type_id = 27
and ticket_history.state_id = 2



group by
SECTOR,
TICKET,
ASSUNTO
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar