黑灬Black 发表于 2011-3-23 22:02:11

语法有问题

ming_xu 发表于 2011-5-12 22:41:09

看不懂,学习中

huzi5182000 发表于 2011-6-8 11:29:36

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

huzi5182000 发表于 2011-6-8 11:32:45

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

mawenjun0504 发表于 2011-7-14 10:15:58

你写的语句比较混乱,下面是我整理好的语句,你看看
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

ˊx.____Q. 发表于 2011-8-5 11:30:24

还是没有看懂 哎

498098148 发表于 2011-10-24 21:50:09

来学习学习,请多多关照:):):)
页: 1 [2]
查看完整版本: SQL数据库语句问题