-2

我有一张这样的桌子:

顾客:

 customerID     joineddate                    
 111            2004-12-10 00:00:00.000
 111            2004-12-10 00:00:00.000
 111            2004-12-10 00:00:00.000 
 211            2004-12-10 00:00:00.000
 231            2004-12-10 00:00:00.000 
 231            2004-11-10 00:00:00.000 
 411            2008-12-10 00:00:00.000
 531            2009-12-10 00:00:00.000 

我已经从 2 个表中编写了查询,我在这些表中进行了连接并获得了类似上面的结果。但我需要得到这样的结果,我需要输入我的条件并得到如下结果。

 customerID     joineddate                 indicator      
 111            2004-12-10 00:00:00.000     3
 211            2004-12-10 00:00:00.000     1
 231            2004-12-10 00:00:00.000     1
 231            2004-11-10 00:00:00.000     1
 411            2008-12-10 00:00:00.000     1
 531            2009-12-10 00:00:00.000     1
4

2 回答 2

1

完全不知道您的其他表的名称或它与customer表的关系,这是我最好的猜测:

SELECT c.customerID, o.joineddate, indicator = COUNT(*)
  FROM dbo.customer AS c
  INNER JOIN dbo.[other table] AS o
  ON c.CustomerID = o.CustomerID
  GROUP BY c.customerID, o.joineddate;
于 2012-04-16T14:47:47.227 回答
1

谷歌搜索关键字

GROUP BY

COUNT()

功能。

于 2012-04-16T14:49:29.210 回答