SQL语句简单问题

win2000pega 2007-11-28 02:26:05
下面的SQL,哪里错了?

select * from
(
select
iod.goods_id,
DATENAME(year, io.goods_out_date),
-1*sum(iod.goods_count)
from
goods_in_out_detail IOD
inner join goods_in_out IO on io.goods_in_out_id=iod.goods_in_out_id
where
iod.in_out_type like '%入库%'
and iod.bill_state<>'2'
and io.bill_state<>'3'
and io.goods_out_date is not null
group by iod.goods_id,DATENAME(year, io.goods_out_date)
) I
...全文
89 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kk19840210 2007-11-28
  • 打赏
  • 举报
回复
io [io]


select * from
(
select
iod.goods_id,
datename(year, io.goods_out_date),
-1*sum(iod.goods_count)
from
goods_in_out_detail IOD
inner join goods_in_out [IO] on io.goods_in_out_id=iod.goods_in_out_id
where
iod.in_out_type like '%入库%'
and iod.bill_state <> '2'
and io.bill_state <> '3'
and io.goods_out_date is not null
group by iod.goods_id,datename(year, io.goods_out_date)
) I
chuifengde 2007-11-28
  • 打赏
  • 举报
回复
对了,没有指定列名,外层的select语句没有必要要啊
fellowcheng 2007-11-28
  • 打赏
  • 举报
回复
up
OracleRoob 2007-11-28
  • 打赏
  • 举报
回复
必须为子查询中的列指定别名,如:


select *
from (select getdate()) as t --没有为子查询指定别名,报错



select *
from (select getdate() as a) as t --为子查询的列指定别名,正确
chuifengde 2007-11-28
  • 打赏
  • 举报
回复
似乎没错,莫非你的goods_out_date有不是日期的格式?
OracleRoob 2007-11-28
  • 打赏
  • 举报
回复
--try


select * from
(
select
iod.goods_id,
DATENAME(year, io.goods_out_date) as t1,
-1*sum(iod.goods_count) as t2
from
goods_in_out_detail IOD
inner join goods_in_out [IO] on io.goods_in_out_id=iod.goods_in_out_id
where
iod.in_out_type like '%入库%'
and iod.bill_state <> '2'
and io.bill_state <> '3'
and io.goods_out_date is not null
group by iod.goods_id,DATENAME(year, io.goods_out_date)
) I
nobody@noone 2007-11-28
  • 打赏
  • 举报
回复
你报错是在哪一行?
貌似楼上说的io每问题啊
我用自己的表

select * from tb io where io.id >1000

这个是可以到
OracleRoob 2007-11-28
  • 打赏
  • 举报
回复
io

-->

[io]

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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