Created
December 10, 2013 14:56
-
-
Save viniciusss/7891923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
explain | |
SELECT `esn`.*, | |
`ete`.`descricao` AS `tp_emis_descricao`, | |
`dest`.`cnpj_cpf` AS `dest_cnpj_cpf`, | |
`sc`.`state` AS `dest_uf_sigla`, | |
`nota_fiscal`.`id` AS `id`, | |
`nota_fiscal`.`emissor_tp_emis_id` AS `emissor_tp_emis_id`, | |
`nota_fiscal`.`emissor_versao_id` AS `emissor_versao_id`, | |
`nota_fiscal`.`emissor_status_nf_id` AS `emissor_status_nf_id`, | |
`nota_fiscal`.`storeno` AS `storeno`, | |
`nota_fiscal`.`spedcidno` AS `spedcidno`, | |
`nota_fiscal`.`chave` AS `chave`, | |
`nota_fiscal`.`cNF` AS `cNF`, | |
`nota_fiscal`.`natOp` AS `natOp`, | |
`nota_fiscal`.`indPag` AS `indPag`, | |
`nota_fiscal`.`mod` AS `mod`, | |
`nota_fiscal`.`serie` AS `serie`, | |
`nota_fiscal`.`nNF` AS `nNF`, | |
`nota_fiscal`.`dEmi` AS `dEmi`, | |
`nota_fiscal`.`dSaiEnt` AS `dSaiEnt`, | |
`nota_fiscal`.`hSaiEnt` AS `hSaiEnt`, | |
`nota_fiscal`.`tpNF` AS `tpNF`, | |
`nota_fiscal`.`tpImp` AS `tpImp`, | |
`nota_fiscal`.`cDV` AS `cDV`, | |
`nota_fiscal`.`tpAmb` AS `tpAmb`, | |
`nota_fiscal`.`finNFe` AS `finNFe`, | |
`nota_fiscal`.`procEmi` AS `procEmi`, | |
`nota_fiscal`.`verProc` AS `verProc`, | |
`nota_fiscal`.`dhCont` AS `dhCont`, | |
`nota_fiscal`.`xJust` AS `xJust`, | |
`nota_fiscal`.`local_retirada_diferente` AS `local_retirada_diferente`, | |
`nota_fiscal`.`local_entrega_diferente` AS `local_entrega_diferente`, | |
`nota_fiscal`.`cnpj` AS `cnpj`, | |
`nota_fiscal`.`autorizacao` AS `autorizacao`, | |
`nota_fiscal`.`cod_autorizacao` AS `cod_autorizacao`, | |
`nota_fiscal`.`impresso` AS `impresso`, | |
`nota_fiscal`.`cancelada_internamente` AS `cancelada_internamente`, | |
`nota_fiscal`.`tipoEmissao` AS `tipoEmissao` | |
FROM `webpdv`.`nota_fiscal` `nota_fiscal` | |
INNER JOIN `webpdv`.`emissor_status_nf` `esn` FORCE INDEX(PRIMARY) ON | |
( esn.id = nota_fiscal.emissor_status_nf_id) | |
INNER JOIN `webpdv`.`emissor_tp_emis` `ete` FORCE INDEX(PRIMARY) ON | |
( ete.id = nota_fiscal.emissor_tp_emis_id) | |
INNER JOIN `webpdv`.`nota_fiscal_dest` `dest` ON | |
( dest.nota_fiscal_id = nota_fiscal.id) | |
INNER JOIN `sqldados`.`spedcid` `sc` ON | |
( sc.no = nota_fiscal.spedcidno) | |
WHERE 1=1 | |
AND storeno = 30 | |
AND tipoEmissao = 'Propria' | |
AND emissor_status_nf_id IN(1, 2, 3, 4, 5, 6, 7,8, 11) | |
AND ((emissor_status_nf_id != 8 AND impresso = 0) OR (emissor_status_nf_id = 8 AND cancelada_internamente = 0 )) | |
GROUP BY nota_fiscal.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment