谢谢楼上的,真晕啊,mysql玩不明白,怎么写都说语法错

解决方案 »

  1.   

    我没有想到好的办法....你看能不能select * from table order by  desc然后循环,每一次计数,到uid=4的时候终止,看看吗个数就是mc
      

  2.   

    4.0是不支持子查询, 4.1以上就支持了要么你先查出uid,再查mc咯. 
    我以前是这么做的
      

  3.   

    你这是查出来的吗?是你自己定义出来的吧
    mysql还没这么智能。简单的说:你可以认为uid的名次是2,也可以认为是3
      

  4.   

    不如先把uid取出来,select count(id) where >uid
      

  5.   

    iasky(C#_ASP_PHP)的方法还算可行,但是这已经属于程序范畴了不属于数据库范畴了吧
      

  6.   

    to:itian(没有靠背的椅) ,没看懂你什么意思,我就是想查uid=4的排名是第几,不能查吗?是sqlserver的话,一个子查询,很简单就出来了
      

  7.   

    4.0不支持子查询,没有办法,至少两次查询阿wasuka(被奴役的食尸鬼) 说的对,可以用conut,如果只查一个uid的mc
      

  8.   

    也是group by 出来的,select count(id) where >uid这种也不行。
    正常数据应该是
    uid      
    1         7
    1         6
    2         3
    2         2
    2         5
    3         4
    3         3
    4         8
    4         1
    4         3
    我就是想查uid=4的总分的排名
      

  9.   

    不知道uid=4的总分是不是8+1+3?
      

  10.   

    先求出总和
    $query = mysql_query("select uid,sum() as  from table group by uid order by  desc");
    $mc = 0;
    while($res = mysql_fetch_row($query))
    {
        if($res['uid'] != 4) $mc++;
        else break;
    }echo $mc;
      

  11.   

    没想出很好的方法
    select uid, sum() as 1 from table  group by uid order by 1 ASC;
    再用循环找出uid=4的位置
      

  12.   

    推荐你建立另外一个表:uid total
    就是编号和总分。
      

  13.   

    多个insert|update而已,除了多占点空间以外。
      

  14.   

    create table tb 
    (
     uid int,
      int
    )
    insert into tb select 1,9
    union all select 2,5
    union all select 3,8
    union all select 4,6
    select uid,mc=(select count(1) from tb where >(select  from tb where uid=4)) 
    from tb 
    where uid=4
    /*
    uid         mc          
    ----------- ----------- 
    4           2(所影响的行数为 1 行)
    */
      

  15.   

    楼上的兄弟,我的mysql版本是4.0.20,不支持子查询,如果支持那就啥都别说了,唉