我有三张桌子:
Years (YearId,Year)
Months (MonthID,Month)
Date (DateID,YearID,MonthID)
Client (CLientID,ClientName)
Payment (PayID,ClientID,DateID,Amount)
我想将DataGridView填入:
Client Name, Amount, Year, Month
我使用了这个陈述,但它没有用:
Select * From (select Year From Years Where YearID = (Select YearId From Date Where dateID = (Select DateID From Payment))),(Select Month From Months Where Monthid = (Select MonthID From Date Where dateID = (Select DateID From Payment))),(Select ClientName From Client Where ClientID = (Select ClientID From Payment),(Select amont From Payment)
答案 0 :(得分:2)
听起来你只是想使用INNER JOINs
:
SELECT C.ClientName,
P.Amount,
Y.Year,
M.Month
FROM Payment P
INNER JOIN Client C
ON P.ClientID = C.ClientID
INNER JOIN Date D
ON P.DateId = D.DateId
INNER JOIN Years Y
ON D.YearId = Y.YearId
INNER JOIN Months M
ON D.MonthId = M.MonthId
请参阅下文,了解JOINs
的良好直观表示: