[英]Nested sub-query to select from more than tow table
I have three tables: 我有三张桌子:
Years (YearId,Year)
Months (MonthID,Month)
Date (DateID,YearID,MonthID)
Client (CLientID,ClientName)
Payment (PayID,ClientID,DateID,Amount)
I want to fill in DataGridView as: 我想填写DataGridView:
Client Name, Amount, Year, Month
I used this statement but it didn't work: 我使用了这个声明,但它不起作用:
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)
Sounds like you're just looking to use INNER JOINs
: 听起来你只是想使用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
See below for a good visual representation of JOINs
: 请参阅下面的JOINs
的良好直观表示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.