语法错误,分给多点.试试!

zoulipeng 2005-06-07 02:06:38
select STime,SDyp=(
select sum(SDyp) from(
select top 120 SDyp from (SELECT sum(SDyp) as SDyp,STime FROM @REC GROUP BY STime) X
where X.STime>=a.STime
)aa having count(*)=120)
from (SELECT sum(SDyp) as SDyp,STime as STime FROM @REC GROUP BY STime) a


服务器: 消息 207,级别 16,状态 3,行 34
列名 'STime' 无效。
...全文
57 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zoulipeng 2005-06-07
  • 打赏
  • 举报
回复
高手真多.接贴了!
谢谢邹建!
zjcxc 元老 2005-06-07
  • 打赏
  • 举报
回复
--用中间表(如 pbsql(风云) 的)

--按楼主的语句分析,直接这样写也可以:
select STime,SDyp=(
select sum(SDyp) from(
select top 120 SDyp
from (
SELECT sum(SDyp) as SDyp,STime
FROM @REC
GROUP BY STime
) X where X.STime>=a.STime
)aa having count(*)=120)
from @REC a
GROUP BY STime
zjcxc 元老 2005-06-07
  • 打赏
  • 举报
回复
select STime,SDyp=(
select sum(SDyp) from(
select top 120 SDyp from (SELECT sum(SDyp) as SDyp,STime FROM @REC GROUP BY STime) X
where X.STime>=a.STime ---*** 这里嵌套得太深,取不到a.STime
)aa having count(*)=120)
from (SELECT sum(SDyp) as SDyp,STime as STime FROM @REC GROUP BY STime) a
pbsql 2005-06-07
  • 打赏
  • 举报
回复
子查询的字段不能那样引用,用中间表过度一下:
SELECT sum(SDyp) as SDyp,STime as STime into #t FROM @REC GROUP BY STime
select STime,SDyp=(
select sum(SDyp) from(
select top 120 SDyp from #t X
where X.STime>=a.STime
)aa having count(*)=120)
from #t a
drop table #t
Andy__Huang 2005-06-07
  • 打赏
  • 举报
回复
select STime,SDyp=(
select sum(SDyp) from(
select top 120 SDyp from (SELECT sum(SDyp) as SDyp,STime FROM @REC GROUP BY STime) X
where X.STime>=a.STime
)aa having count(*)=120)
from (SELECT sum(SDyp) as SDyp,STime as STime FROM @REC GROUP BY STime) a--->這一行有問題,裡面不是有個變量嗎?
fengfangfang 2005-06-07
  • 打赏
  • 举报
回复
把你的表结构贴出来看看

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧