--
-- Struttura stand-in per le viste `flusso ticket`
--
CREATE TABLE `flusso ticket` (
`IdTicket` int(11)
,`IdModalita` int(11)
,`Data` varchar(10)
,`IdOperatore` bigint(11)
,`Prelevato` datetime
,`Chiamato` datetime
,`Presente` datetime
,`Assente` datetime
,`Accettato` datetime
);

-- --------------------------------------------------------

--
-- Struttura per la vista `flusso ticket`
--

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `flusso ticket` AS select `t`.`ticket_id` AS `IdTicket`,`tt`.`id_modalita` AS `IdModalita`,date_format(`t`.`data`,'%Y-%m-%d') AS `Data`,max((case when (`t`.`utente_id` > 0) then `t`.`utente_id` end)) AS `IdOperatore`,max((case when (`t`.`status` = 3) then `t`.`data` end)) AS `Prelevato`,max((case when (`t`.`status` = 4) then `t`.`data` end)) AS `Chiamato`,max((case when (`t`.`status` = 5) then `t`.`data` end)) AS `Presente`,max((case when (`t`.`status` = 6) then `t`.`data` end)) AS `Assente`,max((case when (`t`.`status` = 7) then `t`.`data` end)) AS `Accettato` from (`ec_tracking_status_ticket` `t` join `ec_ticket_totem` `tt` on((`t`.`ticket_id` = `tt`.`id`))) group by `t`.`ticket_id`;