簡體   English   中英

合並兩個mysql表並將結果放入VB.NET中的datagrid中

[英]Merge two mysql tables and get result into datagrid in VB.NET

我有兩個MySQL表,

tblloanRegistry

LoanID     EMPNumber     Date      Amount     Status
1          1111         2012-10-01  50000        0
2          2222         2012-10-10  10000        1

tblLoanAccount

ID     LoanID     Date     Payment     Interest     Total     Auto     Installment
1         1       2012-10-25  5000         0         5000        0           1
2         1       2012-11-01     0        100         100        1           0
3         1       2012-11-25  5000        100        5100        0           2
4         2       2012-11-25  1500         0         1500        0           1

成員1111的輸出:

Date          Description     Principle    Interest      Balance
2012-10-25    Installment: 1     5000          0           45000
2012-11-01    Interest             0          100          45100
2012-11-25    Installment: 2     5000         100          40000

我嘗試了以下操作,但顯示錯誤。

SELECT tblLoanAccount.Date, tblLoanAccount.Payment, tblLoanAccount.Interest, 
tblLoanAccount.Total, tblLoanAccount.Auto, tblLoanAccount.Installment FROM " &
"tblLoanAccount WHERE tblLoanAccount.EMPNumber=" & cmbEMPNumber.Text & " AND 
tblLoanAccount.LoanID = '1' AND tblLoanAccount.Total <> 0 ORDER BY tblLoanAccount.ID

錯誤:

在此處輸入圖片說明

此錯誤是因為您尚未加入表。

使用此查詢作為您的預期答案。 您應該同時連接兩個表,然后才可以輸出。

SELECT tblLoanAccount.Date, tblLoanAccount.Payment, tblLoanAccount.Interest,
    tblLoanAccount.Total, tblLoanAccount.Auto, tblLoanAccount.Installment,     
    if(Installment = 0, 'Interest', concat('Installment : ', Installment)) as Description
FROM tblLoanAccount 
JOIN tblloanRegistry ON tblloanRegistry.LoanID = tblLoanAccount.LoanID
WHERE tblloanRegistry.EMPNumber= 1111 
    AND tblLoanAccount.LoanID = 1 
    AND tblLoanAccount.Total <> 0 
ORDER BY tblLoanAccount.ID

您的表架構是在此鏈接上創建的。 請通過它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM