Với hai bảng sau:SQL Nhiều tham gia
CREATE TABLE [dbo].[MTCorrelations]
(
[CorrelationID] [int] IDENTITY(1,1) NOT NULL,
[StockA] [nvarchar](5) NOT NULL,
[StockB] [nvarchar](5) NOT NULL,
[Correlation] [float] NOT NULL,
[LengthStr] [nvarchar](5) NOT NULL,
[Date] [datetime] NOT NULL
)
CREATE TABLE [dbo].[Industries]
(
[IndustryID] [int] IDENTITY(1,1) NOT NULL,
[Symbol] [nvarchar](5) NOT NULL,
[Sector] [nvarchar](50) NULL,
[Industry] [nvarchar](50) NULL
)
tôi đang cố gắng để tìm kiếm các ngành công nghiệp của StockA và StockB từ bảng Industries. Tuy nhiên tôi không biết làm thế nào để làm nhiều tham gia. Đây là điều tốt nhất tôi có thể đưa ra:
SELECT TOP 1000
[CorrelationID]
,[StockA]
,[StockB]
,[Correlation]
,b.Industry
,c.Industry
FROM [MarketTopology].[dbo].[MTCorrelations] as a JOIN [MarketTopology].[dbo].[Industries] as b ON a.StockA = b.Symbol
AND a JOIN [MarketTopology].[dbo].[Industries] as c ON a.StockB = c.Symbol
Tôi gặp lỗi trên AND. Cách làm đúng là gì?