SQL问题(在关键字 'SELECT' 附近有语法错误)
SELECTA.*,D.*FROMBK_HEADERAWITH(NOLOCK)LEFTJOIN(SELECTC.BK_NO_ID,SUM(CASEWHENLEFT(C.C...
SELECT A.*,D.*
FROM BK_HEADER A WITH (NOLOCK)
LEFT JOIN
(
SELECT
C.BK_NO_ID,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='2' and C.CONTAINER_TYPE<>'20RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20,
SUM(CASE WHEN C.CONTAINER_TYPE='20RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20RF,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='4' AND C.CONTAINER_TYPE<>'40HC' AND C.CONTAINER_TYPE<>'40RH'AND C.CONTAINER_TYPE<>'40RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40,
SUM(CASE WHEN C.CONTAINER_TYPE='40HC' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40HC,
SUM(CASE WHEN C.CONTAINER_TYPE='40RH' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40RH,
SUM(CASE WHEN LEFT(CONTAINER_TYPE,1)='2' THEN ISNULL(C.QUANTITY,0) ELSE 2*ISNULL(C.QUANTITY,0) END) AS TEU
FROM BK_REQUEST_EQUIPMENTS C WITH (NOLOCK)
GROUP BY C.BK_NO_ID
)AS D
服务器: 消息 156,级别 15,状态 1,过程 IBConigneeList,行 8
在关键字 'SELECT' 附近有语法错误。
这是怎么回事
select A*,D*那边 展开
FROM BK_HEADER A WITH (NOLOCK)
LEFT JOIN
(
SELECT
C.BK_NO_ID,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='2' and C.CONTAINER_TYPE<>'20RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20,
SUM(CASE WHEN C.CONTAINER_TYPE='20RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20RF,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='4' AND C.CONTAINER_TYPE<>'40HC' AND C.CONTAINER_TYPE<>'40RH'AND C.CONTAINER_TYPE<>'40RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40,
SUM(CASE WHEN C.CONTAINER_TYPE='40HC' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40HC,
SUM(CASE WHEN C.CONTAINER_TYPE='40RH' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40RH,
SUM(CASE WHEN LEFT(CONTAINER_TYPE,1)='2' THEN ISNULL(C.QUANTITY,0) ELSE 2*ISNULL(C.QUANTITY,0) END) AS TEU
FROM BK_REQUEST_EQUIPMENTS C WITH (NOLOCK)
GROUP BY C.BK_NO_ID
)AS D
服务器: 消息 156,级别 15,状态 1,过程 IBConigneeList,行 8
在关键字 'SELECT' 附近有语法错误。
这是怎么回事
select A*,D*那边 展开
2个回答
展开全部
left join必须加上ON字句指定连接条件
如果闭野乱A和D没有关联条件,那就这么写
SELECT A.*,D.*
FROM BK_HEADER A WITH (NOLOCK)
LEFT JOIN
(
SELECT
C.BK_NO_ID,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='2' and C.CONTAINER_TYPE<>'20RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20,
SUM(CASE WHEN C.CONTAINER_TYPE='20RF'轿档 THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20RF,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='4' AND C.CONTAINER_TYPE<>'40HC' AND C.CONTAINER_TYPE<>'40RH'AND C.CONTAINER_TYPE<>'40RF'脊码 THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40,
SUM(CASE WHEN C.CONTAINER_TYPE='40HC' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40HC,
SUM(CASE WHEN C.CONTAINER_TYPE='40RH' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40RH,
SUM(CASE WHEN LEFT(CONTAINER_TYPE,1)='2' THEN ISNULL(C.QUANTITY,0) ELSE 2*ISNULL(C.QUANTITY,0) END) AS TEU
FROM BK_REQUEST_EQUIPMENTS C WITH (NOLOCK)
GROUP BY C.BK_NO_ID
)AS D
ON 1=1
如果闭野乱A和D没有关联条件,那就这么写
SELECT A.*,D.*
FROM BK_HEADER A WITH (NOLOCK)
LEFT JOIN
(
SELECT
C.BK_NO_ID,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='2' and C.CONTAINER_TYPE<>'20RF' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20,
SUM(CASE WHEN C.CONTAINER_TYPE='20RF'轿档 THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T20RF,
SUM(CASE WHEN LEFT(C.CONTAINER_TYPE,1)='4' AND C.CONTAINER_TYPE<>'40HC' AND C.CONTAINER_TYPE<>'40RH'AND C.CONTAINER_TYPE<>'40RF'脊码 THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40,
SUM(CASE WHEN C.CONTAINER_TYPE='40HC' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40HC,
SUM(CASE WHEN C.CONTAINER_TYPE='40RH' THEN ISNULL(C.QUANTITY,0) ELSE 0 END) AS T40RH,
SUM(CASE WHEN LEFT(CONTAINER_TYPE,1)='2' THEN ISNULL(C.QUANTITY,0) ELSE 2*ISNULL(C.QUANTITY,0) END) AS TEU
FROM BK_REQUEST_EQUIPMENTS C WITH (NOLOCK)
GROUP BY C.BK_NO_ID
)AS D
ON 1=1
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询