/排名查询(相同数量的排名一样,不同数量的依次递增)/

	  select  F_PBKA_OLDSALORGID,
	sum(case when t0.FBILLTYPEID='57faf492b10d31' then FQTY when t0.FBILLTYPEID='580778655b6d7d' then  -FQTY end) FQTY
	into #kk
	 from 
	(select  FBILLTYPEID,FBILLNO,F_PBKA_DATE,F_PBKA_OLDSALORGID,fid From PBKA_t_BillHead where fid>0) t0 
	inner join (select F_PBKA_BHSAMOUNT,fid,FMATERIALID,FQTY From PBKA_t_GoodsDetail where fid>0) t1 on t0.fid=t1.fid
	INNER JOIN T_BD_MATERIALBASE T2 ON t1.FMATERIALID=t2.FMATERIALID
	where t0.FBILLTYPEID in('57faf492b10d31','580778655b6d7d') 
	and convert(varchar(10),t0.F_PBKA_DATE,21)=convert(varchar(10),getdate(),21) 
	group by F_PBKA_OLDSALORGID,FQTY

    select F_PBKA_OLDSALORGID, (Select Count(distinct FQTY )+1  from #kk Where FQTY>a.FQTY) As 排名   From #kk a where   F_PBKA_OLDSALORGID=@ORGID order by FQTY