select 姓名
,语文,名次1=(select count(distinct 语文) from Base where 语文>=a.语文)
,数学,名次2=(select count(distinct 数学) from Base where 数学>=a.数学)
,物理,名次3=(select count(distinct 物理) from Base where 物理>=a.物理)
from Base
order by 名次1

解决方案 »

  1.   


    select 姓名
    ,语文,名次1=(select count(distinct 语文) from Base where 语文>=a.语文)
    ,数学,名次2=(select count(distinct 数学) from Base where 数学>=a.数学)
    ,物理,名次3=(select count(distinct 物理) from Base where 物理>=a.物理)
    from Base a  --漏写了别名
    order by 名次1
      

  2.   

    --测试--测试数据
    create table Base(姓名 varchar(10),语文 int,数学 int,物理 int)
    insert Base select '张三',80,75,82
    union  all  select '李四',85,76,67
    union  all  select '王五',74,92,79
    union  all  select '赵六',88,88,88
    go--查询
    select 姓名
    ,语文,名次1=(select count(distinct 语文) from Base where 语文>=a.语文)
    ,数学,名次2=(select count(distinct 数学) from Base where 数学>=a.数学)
    ,物理,名次3=(select count(distinct 物理) from Base where 物理>=a.物理)
    from Base a
    order by 名次1
    go--删除测试
    drop table Base /*--测试结果姓名   语文   名次1  数学 名次2 物理  名次3  
    ------ ----- ----- ----- ---- ------ ----- 
    赵六   88    1     88    2     88    1
    李四   85    2     76    3     67    4
    张三   80    3     75    4     82    2
    王五   74    4     92    1     79    3(所影响的行数为 4 行)
    --*/
      

  3.   

    --测试--测试数据
    create table Base(姓名 varchar(10),语文 int,数学 int,物理 int)
    insert Base select '张三',80,75,82
    union  all  select '李四',80,76,67
    union  all  select '王五',74,92,67
    union  all  select '赵六',88,92,88
    go--查询
    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
    go--删除测试
    drop table Base /*--测试结果姓名   语文   名次1 数学  名次2 物理   名次3   
    ----- ------ ----- ----- ----- ----- -------
    赵六   88    1     92    1     88    1
    张三   80    2     75    4     82    2
    李四   80    2     76    3     67    3
    王五   74    4     92    1     67    3(所影响的行数为 4 行)
    --*/
      

  4.   

    我找了一上午,没找到。没想到,下午偶然再这里找到我想要的东西。真的要谢谢楼主和zjcxc(邹建)同时也对zjcxc(邹建)佩服有加