SELECT vq.DM1,c.CKMC,vq.RQ,vq.SPDM,vq.GG1DM,g.GGMC GG1MC,LTRIM(g2.GGMC)GG2MC,vq.SL FHSL, s.SL KCSL FROM VW_QDDBMX AS vq LEFT JOIN SPKCB AS s ON s.CKDM=vq.DM1 AND s.SPDM=vq.SPDM AND s.GG1DM=vq.GG1DM AND s.GG2DM=vq.GG2DM LEFT JOIN CANGKU AS c ON c.CKDM=vq.DM1 LEFT JOIN GUIGE1 AS g ON g.GGDM=vq.GG1DM LEFT JOIN GUIGE2 AS g2 ON g2.GGDM=vq.GG2DM WHERE vq.SPDM IN ('XB605MS','XB6028MS') AND vq.DJMC='渠道调拨单' AND vq.RQ=( SELECT min(vq1.RQ)RQ FROM VW_QDDBMX AS vq1 WHERE vq1.DM1=s.CKDM AND vq1.SPDM= vq.SPDM AND vq1.GG1DM=vq.GG1DM AND vq1.GG2DM=vq.GG2DM GROUP BY vq1.DM1,vq1.SPDM,vq1.GG1DM,vq1.GG2DM ) ORDER BY vq.SPDM,vq.DM1
效果