在表P中有如下三列其中id是标识列
Id   PNO    Ver
1    P001   1
2    P002   1
3    P002   2  
4    P003   1   
5    P003   2 
6    P003   3 
7    P004   1
8    P004   2
9    P004   3
10   P004   4
要求得到 每类PNO中的Ver最大值 结果如下
PNO    Ver     Id   
P001 1 1
P002 2 3
P003 3 6
P004 4 10
具体SQL语句该怎么写
我用select PNO,max(Ver) from P group by PNO的话得不到ID
可偏偏ID很重要求知道的大侠指点下

解决方案 »

  1.   

    select distinct * from 表 t where not exists(
    select 1 from 表 where pno=t.pno and ver>t.ver
    )
      

  2.   

    select * from tb t where not exists(select 1 from tb where PNO=t.PNO and ver>t.Ver )
      

  3.   

    SELECT * 
    FROM TableName a
    WHERE Ver=(
              SELECT MAX(Ver)
              FROM TableName
              WHERE PNo=a.PNo
              )
      

  4.   

    select distinct * from 表 t where not exists(
    select 1 from 表 where pno=t.pno and ver>t.ver
    )
      

  5.   

    SELECT * FROM Table a WHERE Ver=(SELECT MAX(Ver)FROM Table WHERE PNo=a.PNo )
      

  6.   

    select * from tb t where ver = (select max(ver) from tb where pno = t.pno)