gpt4 book ai didi

带有 WHERE 子句的 JOIN 之后的 SQL WHERE 语句

转载 作者:行者123 更新时间:2023-12-05 08:15:25 26 4
gpt4 key购买 nike

我正在尝试选择一些数据,我将 3 个表连接在一起,但其中一个连接有一个 where 语句。完成连接后,我需要添加另一个 where 语句来选择日期范围和位置。我在第二个 WHERE 子句上遇到错误。

  SELECT a.[ID]
,a.[item_no]
,a.[qty]
FROM [MYDB].[dbo].[details] AS a


INNER JOIN [MYDB].[dbo].[delivery] AS b
ON a.[item_no] = b.[item_no]
INNER JOIN [MYDB].[dbo].[options] AS c
ON a.[number] = c.[number]
WHERE a.[item_no] = c.[item_no]

WHERE b.[destination] = 'my destination'
AND b.[date] BETWEEN '2018-10-14' AND '2018-10-15'

非常感谢任何帮助。

谢谢

最佳答案

试试下面

SELECT a.[ID]
,a.[item_no]
,a.[qty]
FROM [MYDB].[dbo].[details] AS a


INNER JOIN [MYDB].[dbo].[delivery] AS b
ON a.[item_no] = b.[item_no]
INNER JOIN [MYDB].[dbo].[options] AS c
ON a.[number] = c.[number]
and a.[item_no] = c.[item_no]

WHERE b.[destination] = 'my destination'
AND b.[date] BETWEEN '2018-10-14' AND '2018-10-15'

关于带有 WHERE 子句的 JOIN 之后的 SQL WHERE 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52777907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com