SQL对两张表做查询,再按其结果以编号为组针对几列添加一行合计
我这里少一个东西,我想按客户编码分组合计,TKS!SELECTCOPTD.TD003as订单日期,COPTC.TC004as客户编号,COPMA.MA002as客户简称,...
我这里少一个东西,我想按客户编码分组合计,TKS!
SELECT COPTD.TD003 as 订单日期,COPTC.TC004 as 客户编号, COPMA.MA002 as 客户简称, COPTC.TC001 as 单别, COPTC.TC002 as 单号, COPTC.TC008 as 交易币种, COPTC.TC009 as 汇率, COPTC.TC012 as 客户单号, COPTD.TD004 as 品号, COPTD.TD005 as 品名, COPTD.TD006 as 规格, COPTD.TD008 as 订单数量, COPTD.TD009 as 已交量, COPTD.TD008-COPTD.TD009 as 订单未交量 , COPTD.TD010 as 单位, COPTD.TD011 as 单价,
COPTD.TD016 as 结束, COPTD.TD037 as 税率, COPTD.TD039 as 税额, COPTD.TDI01 as 本币税前金额, COPTD.TDI02 as 本币税额 FROM COPTC,COPTD , COPMAWHERE COPTC.TC001=COPTD.TD001 AND COPTC.TC002=COPTD.TD002 AND COPTC.TC004=COPMA.MA001 展开
SELECT COPTD.TD003 as 订单日期,COPTC.TC004 as 客户编号, COPMA.MA002 as 客户简称, COPTC.TC001 as 单别, COPTC.TC002 as 单号, COPTC.TC008 as 交易币种, COPTC.TC009 as 汇率, COPTC.TC012 as 客户单号, COPTD.TD004 as 品号, COPTD.TD005 as 品名, COPTD.TD006 as 规格, COPTD.TD008 as 订单数量, COPTD.TD009 as 已交量, COPTD.TD008-COPTD.TD009 as 订单未交量 , COPTD.TD010 as 单位, COPTD.TD011 as 单价,
COPTD.TD016 as 结束, COPTD.TD037 as 税率, COPTD.TD039 as 税额, COPTD.TDI01 as 本币税前金额, COPTD.TDI02 as 本币税额 FROM COPTC,COPTD , COPMAWHERE COPTC.TC001=COPTD.TD001 AND COPTC.TC002=COPTD.TD002 AND COPTC.TC004=COPMA.MA001 展开
2个回答
展开全部
在后面加一个语句:
select COPTC.TC004 客户编号 ,sum(COPTD.TD008-COPTD.TD009) from FROM COPTC,COPTD , COPMA WHERE COPTC.TC001=COPTD.TD001
AND COPTC.TC002=COPTD.TD002
AND COPTC.TC004=COPMA.MA001 group by COPTC.TC004
并用union all 语句合并查询结果,并按客户编号排序
select COPTC.TC004 客户编号 ,sum(COPTD.TD008-COPTD.TD009) from FROM COPTC,COPTD , COPMA WHERE COPTC.TC001=COPTD.TD001
AND COPTC.TC002=COPTD.TD002
AND COPTC.TC004=COPMA.MA001 group by COPTC.TC004
并用union all 语句合并查询结果,并按客户编号排序
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询