如何 Select 不同的记录然后在 C# Access 数据库中对它们进行计数?

How to Select Distinct records then count them in C# Access database?

我有一个 table 叫做 TableA

我希望我的结果是这样的

我的代码

       string query = "Select Column2,Count(*) from (Select DISTINCT Column1 from TableA Group by Column2)"

为了看似简单的任务,我尝试了很多解决方案,但都无济于事。被困了几个小时。希望 Access 2007 允许简单的 Count(Distinct Column1) 等,但事实并非如此。需要帮助和指导。

试试这个:

SELECT column2, Count(*) AS C FROM (SELECT DISTINCT column1 FROM TableA GROUP BY column2) AS D;

所以 dbmitch 评论给了我一个先机,我只是稍微改变了一下。这是解决方案:

"Select Column2,Count(T1.Column1) AS Column3 from (Select Column2,Column1 from TableA Group by Column1,Column2) AS T1 Group by T1.Column2"