谁能帮我看看这个SQL哪错了?
初次使用oracle ,下面的语句是从SQL Server转过来的,我不知道哪错了,调了半天,总是报a1.SH_Code 列名无效? 下面的语句有点长,还希望会oracle 的朋友们能耐心帮我看看,感激不尽,我真的找不出来错,改不好。select cr_code,
cr_name,
SH_Code,
SH_Name,
We_Code,
We_Name,
Wec_ID,
Wec_Name,
SnD_WC_Color,
SnD_WM_Model,
We_Spec,
SnD_Ut_ID,
Ut_Name,
nvl(in_Qtys, 0) as Qty,
nvl(Out_Qtys, 0) as out_Qty,
nvl(Qty, 0) as ptd_Qty
from (select distinct cr_code,
cr_name,
SH_Code,
SH_Name,
We_Code,
We_Name,
Wec_ID,
Wec_Name,
WC_Color as SnD_WC_Color,
WM_Model as SnD_WM_Model,
We_Spec,
Ut_ID as SnD_Ut_ID,
Ut_Name,
(select sum(SnD_Qty) as in_Qtys
from (select distinct SnD_Qty,
StdIn_Detail.SnD_We_Code,
StdIn_Detail.SnD_WC_Color,
StdIn_Detail.SnD_WM_Model,
Sn_StdIn_Code
from StdIn, StdIn_Detail, In_Orders
where Sn_StdIn_Code = SnD_StdIn_Code
and Sn_InO_Code = InO_Code
and to_char(StdIn.CreateDate, 'yyyy-mm-dd') >=
to_char('', 'yyyy-mm-dd')
and to_char(StdIn.CreateDate, 'yyyy-mm-dd') <=
to_char('', 'yyyy-mm-dd')
and StdIn_Detail.SnD_We_Code = a1.We_Code
and nvl(StdIn_Detail.SnD_WC_Color, '') =
nvl(a1.WC_Color, '')
and nvl(StdIn_Detail.SnD_WM_Model, '') =
nvl(a1.WM_Model, '')
and InO_Cr_Code = a1.Cr_Code
and InO_SH_Code = a1.Sh_Code) AA
group by SnD_We_Code, SnD_WC_Color, SnD_WM_Model) in_Qtys,
(select nvl(sum(StD_Qty), 0) as out_Qty
from (select distinct StD_Qty,
StD_Ware_Code,
StD_WC_Color,
StD_WM_Model,
StD_StdOut_Code
from StdOut_Detail b,
StdOut b1,
Out_Orders b2
where b.StD_StdOut_Code = b1.St_StdOut_Code
and b1.St_OutO_Code = b2.OutO_Code
and b1.St_Status = 1
and to_char(b1.CreateDate, 'yyyy-mm-dd') >=
to_char('yyyy-mm-dd')
and to_char(b1.CreateDate, 'yyyy-mm-dd') <=
to_char('', 'yyyy-mm-dd')
and b.StD_Ware_Code = a1.We_Code
and b2.OutO_SH_Code = a1.Sh_Code
and nvl(b.StD_WC_Color, '') =
nvl(a1.WC_Color, '')
and nvl(b.StD_WM_Model, '') =
nvl(a1.WM_Model, '')
and b2.OutO_Cr_Code = a1.cr_code) DD
group by StD_Ware_Code, StD_WC_Color, StD_WM_Model) Out_Qtys,
(select sum(Ptd_Qty) as Qty
from (select distinct Ptd_StdIn_Code,
Ptd_Pt_Code,
Ptd_We_Code,
Ptd_Qty,
Ptd_WC_Color,
Ptd_WM_Model
from Pallet_Detail,
Pallet_Use_Detail,
StdIn,
In_Orders
where Ptd_Ptud_ID = Ptud_ID
and Ptud_Status <> 2
and Ptd_StdIn_Code = Sn_StdIn_Code
and Sn_InO_Code = InO_Code
and Ptud_Sh_Code = a1.Sh_Code
and InO_Cr_Code = a1.cr_code
and Ptd_We_Code = a1.We_Code /*无效列名*/
and nvl(Ptd_WC_Color, '') =
nvl(a1.WC_Color, '')
and nvl(Ptd_WM_Model, '') =
nvl(a1.WM_Model, '')) gg
group by Ptd_We_Code, Ptd_WC_Color, Ptd_WM_Model) Qty
from (select distinct SH_Code,
SH_Name,
cr_code,
cr_name,
We_Code,
We_Name,
Wec_ID,
Wec_Name,
WC_Color,
WM_Model,
We_Spec,
Ut_ID,
Ut_Name
from (select distinct SH_Code,
SH_Name,
cr_code,
cr_name,
We_Code,
We_Name,
Wec_ID,
Wec_Name,
SnD_WC_Color as WC_Color,
SnD_WM_Model as WM_Model,
We_Spec,
Ut_ID,
Ut_Name
from StdIn,
StdIn_Detail,
In_Orders,
In_Orders_Detail,
Customer,
Ware,
Ware_Category,
Store_House,
Unit
where InO_SH_Code = SH_Code
and Sn_StdIn_Code = SnD_StdIn_Code
and Sn_InO_Code = InO_Code
and InO_Code = InOD_InO_Code
and InO_Cr_Code = Cr_Code
and SnD_We_Code = We_Code
and We_Wec_ID = Wec_ID
and SnD_Ut_ID = Ut_ID
and Sn_Status = 1
and to_char(StdIn.CreateDate, 'yyyy-mm-dd') >=
to_char('', 'yyyy-mm-dd')
and to_char(StdIn.CreateDate, 'yyyy-mm-dd') <=
to_char('', 'yyyy-mm-dd')
union
select distinct SH_Code,
SH_Name,
cr_code,
cr_name,
We_Code,
We_Name,
Wec_ID,
Wec_Name,
StD_WC_Color as WC_Color,
StD_WM_Model as WM_Model,
We_Spec,
Ut_ID,
Ut_Name
from StdOut,
StdOut_Detail,
Out_Orders,
Customer,
Ware,
Ware_Category,
Store_House,
Unit
where St_StdOut_Code = StD_StdOut_Code
and St_OutO_Code = OutO_Code
and OutO_Cr_Code = cr_code
and StD_Ware_Code = We_Code
and We_Wec_ID = Wec_ID
and St_SH_Code = Sh_Code
and StD_Ut_ID = Ut_ID
and St_Status = 1
and to_char(StdOut.CreateDate, 'yyyy-mm-dd') >=
to_char('', 'yyyy-mm-dd')
and to_char(StdOut.CreateDate, 'yyyy-mm-dd') <=
to_char('', 'yyyy-mm-dd')) a) a1) a2