最后是:select 姓名
,语文,名次1=(select count(语文) from Base where 语文>a.语文)+1
,数学,名次2=(select count(数学) from Base where 数学>a.数学)+1
,物理,名次3=(select count(物理) from Base where 物理>a.物理)+1
from Base a
order by 名次1
应该主要是
名次1=(select count(语文) from Base where 语文>a.语文)+1
不理解吧(select count(语文) from Base where 语文>a.语文)
就是语文比当前这个人高的个数,再+1不就是他的语文名次了吗可一改写成
名次1=(select count(语文) from as b Base where b.语文>a.语文)+1
也许好理解些

解决方案 »

  1.   

    select count(distinct 语文) from Base where 语文>=a.语文  from   base a
      小弟主要是这个不理解???
      

  2.   

    to  :  pengda1i(冒牌大力 V0.2) 
        你帮帮小弟吧!
       多谢! 上面的那个语句还可以以那种形式写呀,为了容易看懂!
      

  3.   

    select count(distinct 语文) from Base where 语文>=a.语文  from   base a
      小弟主要是这个不理解???首先统计base表里的总记录,而且分数为不相同,并且当前记录要大于或者等于里面所说语文总分的记录的条件,查出有几条,就是他的名次.这样的话,排名不是很好.如果第二名有相同的分数.就会出现1,2,2,3.但去掉distinct这个语句.然后where条件改为 where 语文>a.语文)+1就成了1,2,2,4.这样就正确呢