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

Que tal ter acesso a um e-book gratuito que vai te ajudar muito nesse momento decisivo?

Ver ebook

Recomendado pra quem ainda não iniciou o estudos.

Eu quero
Ver ebook

Recomendado para quem está passando por dificuldades nessa etapa inicial

Eu quero

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

Aceitar