id,type_id,phone三个字段,计算type_id相同的不同phone的个数
比如说
id type_id phone
1 1 123456
2 1 123
3 2 321
4 2 1234
5 2 456789结果应该是“1”的时候是一个,“2”的时候是三个
麻烦大家帮个忙给看下

解决方案 »

  1.   

    select type_id,count(*) from (
    select type_id,phone from tt group by type_id,phone) group by type_id
      

  2.   

    select type_id, count(distinct phone) as amonut
    from table
    group by type_id
      

  3.   

    不好意思我的是错的。。
    mysql里面distinct 只能针对记录。
      

  4.   

    to wwwwb:
    报错,every derived table must have its own好像是需要一个别名,怎么弄啊?
      

  5.   

    推荐lz看看这篇文章:
    http://mysql.chinahtml.com/2006/mysql-11459225284269.shtml
      

  6.   

    我的SQL语句在JET SQL、VFP下没有问题,思路是一样的,自行修改为你的
    数据库支持的SQL语句
      

  7.   

    to wwwwb
    谢谢,解决了,在后面加了个“T”,呵呵谢谢你