日期:2014-05-19  浏览次数:20819 次

SQL语句问题,请大家帮帮
select   MC007   AS   成品库存量   from   INVMC   right   JOIN     (select   TC004   AS   客户编号   ,TD004   AS   品号,TD005   as   品名,TD006   AS   规格,sum(TD008-TD009)   AS   未交量   from   COPTC   JOIN   COPTD   ON   RTRIM(COPTC.TC001)+RTRIM(COPTC.TC002)=RTRIM(COPTD.TD001)+RTRIM(COPTD.TD002)     WHERE   TD016= 'N '   AND   TD021= 'Y '   AND   TD008-TD009> 0   group   by   TC004,TD004,TD005,TD006)   ON   RTRIM(TD004)=RTRIM(MC001)   WHERE   MC002= '001 '  
以上语句有错,应如何使用   ,谢谢

------解决方案--------------------
select MC007 AS 成品库存量
from INVMC right JOIN (select TC004 AS 客户编号 ,TD004 AS 品号,TD005 as 品名,TD006 AS 规格,sum(TD008-TD009) AS 未交量
from COPTC JOIN COPTD ON RTRIM(COPTC.TC001)+RTRIM(COPTC.TC002)=RTRIM(COPTD.TD001)+RTRIM(COPTD.TD002)
WHERE TD016= 'N ' AND TD021= 'Y ' AND TD008-TD009> 0
group by TC004,TD004,TD005,TD006
) tt --这个地方给查询加个别名
ON RTRIM(品号)=RTRIM(MC001) --这个地方还有问题:TD004应该改为子查询中的列名
WHERE MC002= '001 '