导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

下面的这个如何写成嵌套的SQL语句

licher 2003-12-10 04:47:48
非嵌套的SQL语句:

insert into %s
select A.JcNo, B.QdName, C.CcKindName, Sum(A.Distance) as Distance,
Sum(A.Degree) as Degree, sum(A.Wdistance) as WDistance,
Sum(A.Power) as Power
from %s as A, %s as B, %s as C
where A.QdNo=B.QdNo and A.CcKind=C.CcKindNo
group by A.JcNo,B.QdName,C.CcKindName
order by A.JcNo ASC, B.QdName ASC, C.CcKindName ASC
...全文
5 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
licher 2003-12-12
不过,邹建大哥的那种写法有问题?
回复
licher 2003-12-12
楼上老兄:
不知道邹建大哥的写法效率如何?
我是认为嵌套的SQL效率最高,你意见如何?
回复
其实楼主的那种写法是效率最高的.
回复
select jcno
,qdname=(select qdname from %s where QdNo=a.QdNo)
,CcKindName=(select qdname from %s where CcKind=a.CcKind)
,Sum(A.Distance) as Distance
,Sum(A.Degree) as Degree
,sum(A.Wdistance) as WDistance
,Sum(A.[Power]) as [Power ]
from %s a
group by jcno,qdname,CcKindName
order by JcNo,QdName,CcKindName
回复
CrazyFor 2003-12-10
什么是嵌套的SQL语句啊?
回复
txlicenhe 2003-12-10
就象楼主的写法挺好啊。
改为JOIN:
insert into %s
select A.JcNo, B.QdName, C.CcKindName, Sum(A.Distance) as Distance,
Sum(A.Degree) as Degree, sum(A.Wdistance) as WDistance,
Sum(A.Power) as Power
from %s as A
join %s as B on A.QdNo=B.QdNo
join %s as C on A.CcKind=C.CcKindNo
--where A.QdNo=B.QdNo and A.CcKind=C.CcKindNo
group by A.JcNo,B.QdName,C.CcKindName
order by A.JcNo ASC, B.QdName ASC, C.CcKindName ASC
回复
licher 2003-12-10
中间的:%s分别代表一个表名。
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告