这是我坚持的查询
Select vendor,
F.airline_code,
F.invoice_nmr invoice_vendor,
F.booking_nmr,
sum(amount) total_factura ,
IF(tipo = 'CH',facturado,pagado) monto_pagado,
tipo,
concat(b_month,'-',b_year) periodo_factura,
F.fecha_carga,
date awb_date,
count(*) Reg
from p24l3dbd_costos.PAGOS G
RIGHT JOIN p24l3dbd_costos.FACTURAS F ON F.booking_nmr = G.booking_nmr and F.airline_code = G.airline_code
LEFT JOIN p24l3dbd_costos.GUIAS_ID I ON F.booking_nmr = I.booking_nmr and F.airline_code = I.id_ch
group by F.airline_code,F.invoice_nmr,F.booking_nmr,F.fecha_carga
order by F.select *, CASE
WHEN vendor is null THEN 'Sin Guia' ELSE 'Con Guia' END estado_factura,
CASE WHEN dif <=-5 or vendor is null THEN 'A Disputar' ELSE 'A Pagar' END pagar
from (Select vendor ,airline_code ,invoice_nmr invoice_vendor,F.booking_nmr,date awb_date,F.ori,F.dest ,accrual_cost provision
,pagado total_pagado,facturado total_facturado,
IF(G.tipo='CH',(accrual_cost-pagado),(accrual_cost-pagado-sum(amount))) dif,
sum(amount) ultima_factura ,nmr_pago ,weight vendor_chw,booking_chw awb_chw,spotref,
concat(substring(billing_per_begin,1,2),'-',substring(billing_per_begin,9,2)) periodo_guia,
concat(b_month,'-',b_year) periodo_factura,tipo,fecha_carga
from p24l3dbd_costos.GUIAS_ID G
RIGHT JOIN p24l3dbd_costos.FACTURAS F
ON F.booking_nmr = G.booking_nmr and F.airline_code = G.id_ch
group by F.airline_code,F.invoice_nmr,F.booking_nmr,fecha_carga) x
order by vendor, (str_to_date(fecha_carga,'%m/%d/%Y')) DESC, vendor desc,
如果我尝试运行它,我会收到以下错误消息:`
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'CASE WHEN供应商是零那么'Sin Guia'ELSE'Con Guia'END estado_factura,'第8行
`