表caifuc有uid  tid     type  字段。我在输出的时候如何得到tid相同的值的总数?如得到TID字段值15091 的总数为4条记录?uid  tid     type  
76  15087     2 
76  15091     7 
76  14866     1 
76  15082     3 
76  15091     3 
76  15091     8 
76  15091     2 
76  15082     1 

解决方案 »

  1.   

    select tid ,count(tid) as num from caifuc group by tid;
      

  2.   

    然后怎么输出呢。ASP是<%=rs.RecordCount%>
    PHP我不知道怎么写.呵呵。
      

  3.   


    mysql_connect('localhost','username','password');
    mysql_select_db('mydb');
    $result = mysql_query('SELECT `tid`, COUNT(`tid`) FROM `caifuc` GROUP BY `tid`');
    if ($result && mysql_num_rows($result) > 0)
    {
    while ($row = mysql_fetch_row($result))
    {
    echo 'tid: ', $row[0], ' num: ', $row[1], '<br/>';
    }
    }
      

  4.   

    select count(distinct tid) as count1 from table 第一个select count(1) from table where tid=15091 第二个,
    上面只是思路!