create table jf_sa_fahuobiao (cCuscodeVARCHAR(20), cCusName VARCHAR(98),isummoney,qc money)
Insert into jf_sa_fahuobiao (ccuscode,cCusName,isum,qc)
select x.cCuscode,max(x.cCusName ),sum(x.isum) from (
select DispatchList.cCuscode as cCuscode,DispatchList.cCusName cCusName, DispatchLists.isum as isumfrom DispatchList right JOIN DispatchLists on DispatchList.DLID = DispatchLists.DLID WHERE (dDate >= CONVERT(DATETIME, '2009-11-17 00:00:00', 102)) and (dDate <= CONVERT(DATETIME, '2010-04-17 00:00:00', 102))
) x groupx.cCuscode
drop table jf_sa_fahuobiao
create table jf_sa_fahuobiao (cCuscodeVARCHAR(20), cCusName VARCHAR(98),isummoney,qc money)
Insert into jf_sa_fahuobiao (ccuscode,cCusName,isum,qc)
select x.cCuscode,max(x.cCusName ),sum(x.isum) from (
select DispatchList.cCuscode as cCuscode,DispatchList.cCusName cCusName, DispatchLists.isum as isumfrom DispatchList right JOIN DispatchLists on DispatchList.DLID = DispatchLists.DLID WHERE (dDate >= CONVERT(DATETIME, '2009-11-17 00:00:00', 102)) and (dDate <= CONVERT(DATETIME, '2010-04-17 00:00:00', 102))
) x groupx.cCuscode
你写的语句比较混乱,下面是我整理好的语句,你看看
create table jf_sa_fahuobiao (cCuscodeVARCHAR(20), cCusName VARCHAR(98),isummoney,qc money)
Insert into jf_sa_fahuobiao (ccuscode,cCusName,isum,qc)
select DispatchList.cCuscode,DispatchList.cCusName, sum(DispatchLists.isum) isum,a.isum qc
from DispatchList
right JOIN DispatchLists on DispatchList.DLID = DispatchLists.DLID
inner join (selectsum(DispatchLists.isum) isum,ccuscode from DispatchList right JOIN DispatchLists on DispatchList.DLID = DispatchLists.DLID
WHERE (dDate < CONVERT(DATETIME, '2009-11-17 00:00:00', 102))and DispatchList.ccusname is not null
GROUP BY ccuscode ) a on DispatchList.ccuscode = a.ccuscode
WHERE (dDate >= CONVERT(DATETIME, '2009-11-17 00:00:00', 102)) and (dDate <= CONVERT(DATETIME, '2010-04-17 00:00:00', 102))
and DispatchList.ccusname is not null
GROUP BY DispatchList.ccuscode,DispatchList.cCusName,a.isum 还是没有看懂 哎 来学习学习,请多多关照:):):)
页:
1
[2]