CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`ticketPreviousPreparingList` AS SELECT `s`.`ticketFk` AS `ticketFk`, `w`.`code` AS `code`, COUNT(`s`.`id`) AS `saleLines`, sum(`s`.`isPicked` <> 0) AS `alreadyMadeSaleLines`, sum(`s`.`isPicked` <> 0) / COUNT(`s`.`id`) AS `madeRate`, `sg`.`created` AS `created`, `p`.`code` AS `parking`, `iss`.`sectorFk` AS `sectorFk`, `al`.`code` AS `alertCode` FROM ( ( ( ( ( ( ( `vn`.`saleGroup` `sg` JOIN `vn`.`saleGroupDetail` `sgd` ON(`sgd`.`saleGroupFk` = `sg`.`id`) ) JOIN `vn`.`sale` `s` ON(`s`.`id` = `sgd`.`saleFk`) ) JOIN `vn`.`ticketState` `tls` ON(`tls`.`ticketFk` = `s`.`ticketFk`) ) JOIN `vn`.`alertLevel` `al` ON(`al`.`id` = `tls`.`alertLevel`) ) JOIN `vn`.`worker` `w` ON(`w`.`id` = `sg`.`userFk`) ) LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sg`.`parkingFk`) ) JOIN `vn`.`itemShelvingStock` `iss` ON(`iss`.`itemFk` = `s`.`itemFk`) ) WHERE `sg`.`created` >= `util`.`VN_CURDATE`() + INTERVAL 0.1 DAY GROUP BY `sg`.`id`