我想检索每个供应商的总账单和付款,以便在这样的报告中显示它们:
和我的数据库表关系是:
我从查询中得到的结果与正确的结果相比非常大! 这是我的问题:
Dim strSQL As String
strSQL = "SELECT c.sup_Name, c.sup_Place, SUM(a.bill_Total), SUM(d.pa_Value), c.sup_Id " & _
"FROM (suppliers c LEFT JOIN bills a on c.sup_Id = a.bill_From) LEFT JOIN payments d ON c.sup_Id = d.pa_To " & _
"WHERE (c.sup_Name LIKE '%" + txbSearch.Text + "%' OR c.sup_Place LIKE '%" + txbSearch.Text + "%') AND " & _
"(a.bill_Date >= #" + txbFrom.Text + "# AND a.bill_Date <= #" + txbTo.Text + "#) AND " & _
"(d.pa_EntryDate >= #" + txbFrom.Text + "# AND d.pa_EntryDate <= #" + txbTo.Text + "#) " & _
"GROUP BY c.sup_Id,c.sup_Name,c.sup_Place " & _
"ORDER BY c.sup_Name asc"
OleDbCommand cmd = new OleDbCommand(strSQL, objConn);
OleDbDataReader dataReader = cmd.ExecuteReader();
我注意到的另一件事: 如果特定供应商的付款表格中有多行,则结果将不正确,但如果只有一笔付款,则结果正确无误。 和票据表一样。