比如:select * from m1 where id=15 order by id desc
查询id编号15信息所在信息总数的第几条,不是使用数据库ID显示,如何写语句呢我查了一下没有想到办法,希望高手可以解答一下谢谢。可能要统计一下信息总数,然后再显示这条信息在总数的提交条,我是这样想的,不知道一条语句可否能简单查询到

解决方案 »

  1.   

    set @ID=0;
    select *,@ID:=@ID+1 from from m1 where id=15 order by id desc;
      

  2.   

    mysql> select *from a_b;
    +------+------+--------+
    | id   | a    | b      |
    +------+------+--------+
    |    1 | asd  | asd12  |
    |    2 | wer  | wer1   |
    |    5 | asd  | asd123 |
    |    6 | xzc  | xzc1   |
    |   33 | fhf  | fhf1   |
    |   45 | asd  | asd2   |
    |   23 | asd  | asd3   |
    |   34 | wer  | wer3   |
    |   55 | qwq  | qwe    |
    +------+------+--------+
    9 rows in set (0.00 sec)mysql> set @c=0;
    Query OK, 0 rows affected (0.00 sec)mysql> select * from (
        -> select *,@c:=@c+1 as num from a_b
        -> ) a where id=33;
    +------+------+------+------+
    | id   | a    | b    | num  |
    +------+------+------+------+
    |   33 | fhf  | fhf1 |    5 |
    +------+------+------+------+
    1 row in set (0.00 sec)
      

  3.   

    mysql> set @c=0;mysql> select * from 
        ->(
        -> select *,@c:=@c+1 as num from a_b order by id desc 
        -> ) a 
        ->where id=33;
      

  4.   

    create temporary table tmp_table(id int auto_increment,b int
    )type=memory
    insert into temp_table(b)
    select id from m1select count(*) from temp_table
    select id from temp_table where b=15
      

  5.   

    5L的子查询没排序  只是数据凑巧...LZ 结贴真快