create table tb(id int)insert into tb values(10)insert into tb values(20)insert into tb values(30)insert into tb values(11)insert into tb values(12)
select * , px = (select count(1) from tb where id < t.id) + 1 from tb t order by px
这里的t.id指的是什么??

解决方案 »

  1.   

    select * , px = (select count(1) from tb where id < t.id) + 1 from tb t order by px指外层的表tb
      

  2.   

    where id < t.id前一个id是(select count(1) from tb where id < t.id)这个tb表的
    后一个t.id是(select * , px=... from tb t order by px)这个tb表的
      

  3.   

    select * , px = (select count(1) from tb where id < t.id) + 1 from tb t order by px
    t.id是指外层的(select * ,px...from tb t order by px)这里的表tb
      

  4.   

    create table tb(id int)
    insert into tb values(10)
    insert into tb values(20)
    insert into tb values(30)
    insert into tb values(11)
    insert into tb values(12)select * ,t.id,
    px = (select count(1) from tb where id < t.id) + 1 
    from tb t 
    order by px