Select Num=(select count(*) from 表 where PId+PName<a.PId+a.PName)+1,
       PId,PName from 表 as a group by PId,PName order by 1

解决方案 »

  1.   

    create table tb(PId varchar(10),PName varchar(10))
    insert into tb select 'A1','电视'
    union all select 'A6','空调'select [num]=identity(int,300,1),* into # from tb
    select * from #drop table tb,#
    --这样?
      

  2.   

    --如果取出来的结果要想从300开始应该怎么做呢
    -- ??
    select * from
    ( Select Num=(select count(*) from 表 where PId+PName<a.PId+a.PName)+1,
           PId,PName from 表 as a group by PId,PName) x
    where Num>=300 order by Num
      

  3.   

    --不知道是不是理解错了
    create table tb(PId varchar(10),PName varchar(10))
    insert into tb select 'A1','电视'
    union all select 'A6','空调'select [num]=identity(int,1,1),* into # from tb
    select * from # where id>=300drop table tb,#