我有以下 sql,但目前无法转换。我停在子选择的极限处。谁能帮我?
select( select p2.numnfe from xml_itens as p2
where p2.cod_prod_cli is null
and p2.ean_prod = p1.ean_prod
and p2.cnpj_for = p1.cnpj_for
and p2.cod_prod_for = p1.cod_prod_for
and p2.cfop != 5929 and 6929
LIMIT 1
) as num_nfe,
(SELECT descricao_prod from xml_itens as p2
where p2.cod_prod_cli is null
and p2.ean_prod = p1.ean_prod
and p2.cnpj_for = p1.cnpj_for
and p2.cod_prod_for = p1.cod_prod_for
and p2.cfop != 5929 and 6929
LIMIT 1
) as descricao_prod,
cnpj_for, ean_prod, cod_prod_for, cod_prod_cli
from xml_itens as p1
where cod_prod_cli is null
and p1.cfop != 5929 and 6929
group by cnpj_for, ean_prod, cod_prod_for;
我设法做到了,但及时赶上了从数据库中只返回一条记录。
String sql = "select ("
+ " select p2.numnfe from XmlItens p2 where p2.codProdCli is null and p2.eanProd = p1.eanProd and p2.cnpjFor = p1.cnpjFor and p2.cfop != 5929 and p2.cfop != 6929) as numnfe, "
+ " p1.cnpjFor, p1.eanProd, p1.codProdFor from XmlItens p1 "
+ " where p1.codProdCli is null "
+ " group by p1.cnpjFor, p1.eanProd, p1.codProdFor";
谢谢