0

我有三张桌子:

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)
4

1 回答 1

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

JOINS 的可视化表示

于 2013-03-31T01:26:08.523 回答