外面的主要想查询出名次Place字段
如查询到结果SupplyName      tongguo      PlaceTW1        100%     1
sea        100%     1
fds        60%             2
sam        33%      3
SELECT SupplyName,tongguo,Place=(SELECT COUNT(DISTINCT Ran) FROM  (select SupplyName,tongguo,convert(float,tongguoS)  AS   Ran
FROM(select SupplyName,ltrim(sum(case Violation when '1' then 1 when '2' then 1 else 0 end)*100/count(1))+'%' as tongguo, 
ltrim(sum(case Violation when '1' then 1 when '2' then 1 else 0 end)*100/count(1)) as tongguoS 
from Supply_Sign where SignDate >= '2011-12-1' and SignDate <'2012-01-1' group by SupplyName)Supply_Sign 
order by Ran DESC
这一段红色可以查询到以下数据TW1 100% 100sea 100% 100fds 60% 60sam 33% 33
)WHERE Ran>=a.Ran)
FROM tb a
ORDER BY Place以上语句在执行的时候总报错

解决方案 »

  1.   

    tb表有Ran字段吗,估计没有
    用cte,如果是2005+的话
      

  2.   

    自己解决了 希望对以后搜索到这个帖子的人有帮助以后
    SELECT * into #tmpTable from(
    select SupplyName,tongguo,convert(float,tongguoS)  AS   Ran
    FROM(select SupplyName,ltrim(sum(case Violation when '1' then 1 when '2' then 1 else 0 end)*100/count(1))+'%' as tongguo, 
    ltrim(sum(case Violation when '1' then 1 when '2' then 1 else 0 end)*100/count(1)) as tongguoS 
    from Supply_Sign where SignDate >= '2011-12-1' and SignDate <'2012-01-1' group by SupplyName)Supply_Sign 
    )tb
    SELECT SupplyName,tongguo,Ran=(SELECT COUNT(DISTINCT Ran) FROM #tmpTable WHERE Ran>=a.Ran)
    FROM #tmpTable a
    ORDER BY Ran
    drop  table  #tmpTable 
      

  3.   

    外面的主要想查询出名次Place字段
    如查询到结果SupplyName      tongguo      PlaceTW1           100%        1
    sea           100%        1
    fds           60%             2
    sam           33%         3
    SELECT SupplyName,tongguo,Place=(SELECT COUNT(DISTINCT Ran) FROM  (select SupplyName,tongguo,convert(float,tongguoS)  AS   Ran
    FROM(select SupplyName,ltrim(sum(case Violation when '1' then 1 when '2' then 1 else 0 end)*100/count(1))+'%' as tongguo, 
    ltrim(sum(case Violation when '1' then 1 when '2' then 1 else 0 end)*100/count(1)) as tongguoS 
    from Supply_Sign where SignDate >= '2011-12-1' and SignDate <'2012-01-1' group by SupplyName)Supply_Sign 
    order by Ran DESC
    这一段红色可以查询到以下数据TW1    100%    100sea    100%    100fds    60%    60sam    33%    33
    ) ttt --------些处加一个别名看看WHERE Ran>=a.Ran)
    FROM tb a
    ORDER BY Place