27,579
社区成员
发帖
与我相关
我的任务
分享
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
必须为子查询中的列指定别名,如:
select *
from (select getdate()) as t --没有为子查询指定别名,报错
select *
from (select getdate() as a) as t --为子查询的列指定别名,正确
--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
io
-->
[io]