日期:2014-05-18  浏览次数:20509 次

数据统计问题,求指点
SQL code

数据:

ID      PID     UserID Type          Time
714    1276    2771    2    2012-04-14 13:15:02.427
714    1340    2771    2    2012-04-14 13:15:02.427
714    1525    2771    2    2012-04-14 13:15:02.427
714    12011    2771    2    2012-06-14 18:15:09.223
714    12194    2771    2    2012-06-21 14:00:00.000
723    12599    2771    1    2012-07-04 14:00:00.000
723    1289    2771    1    2012-04-14 13:15:02.427
723    2138    2771    1    2012-04-14 13:15:02.427
724    1867    2771    1    2012-04-14 13:15:02.427
724    1928    2771    1    2012-04-14 13:15:02.427
724    1290    2771    1    2012-04-14 13:15:02.427
724    1292    2771    1    2012-04-14 13:15:02.427
724    1323    2771    1    2012-04-14 13:15:02.427
724    12233    2771    1    2012-06-22 11:00:00.000
724    12497    2771    1    2012-07-02 14:00:00.000
724    12207    2771    1    2012-06-21 11:00:00.000
743    12775    2771    1    2012-07-11 11:00:00.000
743    1317    2771    1    2012-04-14 13:15:02.427
743    1531    2771    1    2012-04-14 13:15:02.427
743    1858    2771    1    2012-04-14 13:15:02.427
743    1958    2771    1    2012-04-14 13:15:02.427
813    2036    2771    1    2012-04-14 13:15:02.427
813    2135    2771    1    2012-04-14 13:15:02.427



一名语句,统计出Type为1与2各自的count数,当ID一样时,计为1,请大牛指点,非常感谢

------解决方案--------------------
SQL code
SELECT  
  TYPE,COUNT(DISTINCT ID) AS CNT
FROM
  TB
GROUP BY TYPE