FName                       FPlanPrice
1300*1.2外角钢          51.0000000000
0.75*1000*1700外包板 35.0000000000
0.50*1200*1600外包板 30.0000000000
0.40*1200*1620内包板 25.5000000000
0.40*1200*1620内包板 NULL
1300*1.2外角钢          67.000000000
0.50*1200*1600外包板 NULL
0.75*1000*1700外包板 NULLSQL语句是:select a.FName,a.FPlanPrice from a,b where a.FName=b.FName order by a.FPlanPrice desc 
我现在想查询出第一次出现FName对应的记录,多余的记录舍弃,该如何做呢,我想要达到效果如下:
FName                       FPlanPrice
1300*1.2外角钢          51.0000000000
0.75*1000*1700外包板 35.0000000000
0.50*1200*1600外包板 30.0000000000
0.40*1200*1620内包板 25.5000000000即后面四条记录的FNAME前面已经出现过
请高手指点,谢谢!

解决方案 »

  1.   

    select * from TB T 
    where not eixsts(select 1 from TB where T.FName=FName and T.FPlanPrice>FPlanPrice)
      

  2.   

    select a.FName,max(a.FPlanPrice) from a,b where a.FName=b.FName group by a.FName
      

  3.   

    select Fname,FPlanPrice from 
    (
    select row_number() over(partition by Fname order by getdate()) id,Fname,FPlanPrice from  tb
    ) V
    where v.id=1
      

  4.   

    select 
      *
    from 
      tb T 
    where 
      not eixsts(select 1 from TB where t.FName=FName and t.FPlanPrice>FPlanPrice)
      

  5.   

    b表是用来筛选符合条件的FName的a.FName=b.FName 
      

  6.   

    select a.FName,MAX(a.FPlanPrice) FPlanPrice
    from a,b where a.FName=b.FName GROUP BY 
    a.FName order by a.FPlanPrice desc ???
      

  7.   

    通过以上语句可以查询出我原始的记录
    FName                      FPlanPrice 
    1300*1.2外角钢         51.0000000000 
    0.75*1000*1700外包板 35.0000000000 
    0.50*1200*1600外包板 30.0000000000 
    0.40*1200*1620内包板 25.5000000000 
    0.40*1200*1620内包板 NULL 
    1300*1.2外角钢         12.000000000 
    0.50*1200*1600外包板 NULL 
    0.75*1000*1700外包板 NULL 我的意思是现在想把重复的FNAME的去掉,即就取前4条,该如何在此语句上加工