我想检查表A中的一条记录,以检查它是否存在于表B中。我计算表B中输入了多少数据。
示例:
A B
------------------------------
John John
Joon Jorge
Jorge Joon
Elizabet Elizabet
Suzan Suzan
Elizabet
Joon
Suzan
John
Elizabet答案应该是这样的:
John = 2
Joon = 2
jorge = 1
Elizabet = 3
Suzan = 2我尝试过的:
using (ImportInvoiceMasterForm.ApplicationSqlConnection2 = new SqlConnection(MainForm.ApplicationDataBase))
{
ImportInvoiceMasterForm.ApplicationSqlConnection2.Open();
using (ImportInvoiceMasterForm.ApplicationSqlCommand1 = new SqlCommand("SELECT * FROM TBL_Stock_Item", ImportInvoiceMasterForm.ApplicationSqlConnection2))
using (ImportInvoiceMasterForm.ApplicationSqlDataReader1 = ImportInvoiceMasterForm.ApplicationSqlCommand1.ExecuteReader())
{
while (ImportInvoiceMasterForm.ApplicationSqlDataReader1.Read())
{
ImportInvoiceMasterForm.GetImportQuantity = 0;
#region Get Import Quantity
using (ImportInvoiceMasterForm.ApplicationSqlConnection1 = new SqlConnection(MainForm.ApplicationDataBase))
{
ImportInvoiceMasterForm.ApplicationSqlConnection1.Open();
using (ImportInvoiceMasterForm.ApplicationSqlCommand = new SqlCommand("SELECT * FROM TBL_Import_Items WHERE ImportItemName='" + ImportInvoiceMasterForm.ApplicationSqlDataReader1.GetString(1) + "'", ImportInvoiceMasterForm.ApplicationSqlConnection1))
using (ImportInvoiceMasterForm.ApplicationSqlDataReader = ImportInvoiceMasterForm.ApplicationSqlCommand.ExecuteReader())
{
while (ImportInvoiceMasterForm.ApplicationSqlDataReader.Read())
{
GetImportQuantity += double.Parse(ImportInvoiceMasterForm.ApplicationSqlDataReader.GetValue(4).ToString());
}
}
}
#endregion Get Import Quantity
}
}
}发布于 2020-06-28 20:05:00
Select A.name, Count(B.name) As Num
FROM A join B
Where B.name=A.name
Group By A.name这将为您提供所需的解决方案
https://stackoverflow.com/questions/62622174
复制相似问题