子查询报错?不可以这么写么?
select stk_no,mtype,qty,doc,
(case
when doc = 'PIN ' then qty*-1
else qty
end) as newqty
from spdtran where depart= 'ZZZ ' and item_del= 'N ')
这个出来stk_no,mtype,qty,doc,newqty 5列
然后我外面套一个查询就报错
select stk_no,mtype,newqty from (
select stk_no,mtype,qty,doc,
(case
when doc = 'PIN ' then qty*-1
else qty
end) as newqty
from spdtran where depart= 'ZZZ ' and item_del= 'N ')
') ' 附近有语法错误。
[解决办法]
select stk_no,mtype,newqty from (
select stk_no,mtype,qty,doc,
(case
when doc = 'PIN ' then qty*-1
else qty
end) as newqty
from spdtran where depart= 'ZZZ ' and item_del= 'N ') t --加别名
[解决办法]
select stk_no,mtype,newqty from (
select stk_no,mtype,qty,doc,
(case
when doc = 'PIN ' then qty*-1
else qty
end) as newqty
from spdtran where depart= 'ZZZ ' and item_del= 'N ') A
最後任意加個別名就可以