关于建立数据库视图表student中有以下:student subject gradestudent1 80studen

1个回答

  • 如果表的STUDENT字段和SUBJECT字段为组合关键字,那么这样

    select distinct student,

    语文=isnull((select grade from student b where b.student=a.student and b.subject='语文' ),''),

    数学=isnull((select grade from student c where c.student=a.student and c.subject='数学' ),''),

    英语=isnull((select grade from student d where d.student=a.student and d.subject='英语' ),''),

    from student a

    否则,这样写更保险:

    select distinct student,

    语文=isnull((select max(grade) from student b where b.student=a.student and b.subject='语文' ),''),

    数学=isnull((select max(grade) from student c where c.student=a.student and c.subject='数学' ),''),

    英语=isnull((select max(grade) from student d where d.student=a.student and d.subject='英语' ),''),

    from student a