select 课目 from 表1 join 表2 on 表1.学号=表2.学号
where 表1.班级=2
order by (case when 表2.班级=2 then '' else 表2.班级=2 end)

解决方案 »

  1.   

    不行,不過你可以這麼做:
    1.先將 表2.班级 等于 where条件里班级 的數據插入臨時表
    2. 再將 表2.班级 升序排 插入臨時表
    3. select * from 臨時表 order by id
    注:臨時表有一 id字段, id int identity(1,1)
      

  2.   

    不太清楚你说的,要就是按你说的排序倒是可以做到

    表2.班级 等于 where条件里班级的纪录
    union all
    其余的纪录 order by 表2.班级
      

  3.   

    select 课目 from 表1 join 表2 on 表1.学号=表2.学号
    where 表1.班级=2
    order by (case when 表2.班级=2 then '' else 表2.班级 end)
      

  4.   

    贴点数据给大家研究create table 表1(学号 char(3),班级 char(1))
    insert into 表1 select '101','1'
    union all select '102','1'
    union all select '201','2'
    union all select '202','2'
    union all select '301','3'
    union all select '302','3'
    select * from 表1
    create table 表2(学号 char(3),班级 char(1),课目 char(1))
    insert into 表2 select'201','1','A'
    union all select '201','2','B'
    union all select '201','3','C'select 课目 from 表1 join 表2 on 表1.学号=表2.学号
    where 表1.班级='2'
    order by (case when 表2.班级='2' then '' else 表2.班级 end)
    drop table 表1,表2