我试图寻找我的问题的答案但未能得到实际帮助的答案。 我写了一个sql代码,但似乎无法找到问题所在。 是否可以将子查询放在“FROM”部分?
SELECT S2.ITEM,
S1.SHOP_ORDER,
S1.OPERATION_NO,
S1.START_DATE,
S1.QTY_GOODS,
S1.QTY_ENTERED,
S1.QTY_MRB
FROM (SELECT SHOP_ORD_RPT.OPERATION_NO,
SHOP_ORD_RPT.SHOP_ORDER
FROM FLAME.SHOP_ORD_RPT
WHERE SHOP_ORD_RPT.OPERATION_NO = 110
OR SHOP_ORD_RPT.OPERATION_NO = 370) AS S1
JOIN (SELECT SHOP_ORD.SHOP_ORDER
FROM FLAME.SHOP_ORD
WHERE SHOP_ORD.ITEM = '3A2375'
OR SHOP_ORD.ITEM = '3A2703')AS S2
ON S1.SHOP_ORDER = S2.SHOP_ORDER;
运行脚本时收到的错误是:
SQL命令未正确结束
如果有人能提供帮助我会很感激。 非常感谢你- 露丝
答案 0 :(得分:28)
尝试在{{1and1}}子查询后删除AS
关键字,如下所示
FROM
答案 1 :(得分:9)
可以在from子句中放置子查询。试试这个:
SELECT S2.ITEM,
S1.SHOP_ORDER,
S1.OPERATION_NO,
S1.START_DATE,
S1.QTY_GOODS,
S1.QTY_ENTERED,
S1.QTY_MRB
FROM (SELECT SHOP_ORD_RPT.OPERATION_NO,
SHOP_ORD_RPT.SHOP_ORDER
FROM FLAME.SHOP_ORD_RPT
WHERE SHOP_ORD_RPT.OPERATION_NO = 110
OR SHOP_ORD_RPT.OPERATION_NO = 370) S1,
(SELECT SHOP_ORD.SHOP_ORDER
FROM FLAME.SHOP_ORD
WHERE SHOP_ORD.ITEM = '3A2375'
OR SHOP_ORD.ITEM = '3A2703') S2
WHERE S1.SHOP_ORDER = S2.SHOP_ORDER;