zoukankan      html  css  js  c++  java
  • mysql三表查询sql语句

    1. 表结构:

    Student学生表(学号、姓名、性别、年龄、编辑)

    Course课程表(编号、课程名称)

    sc选课表(选课编号、学号、课程编号、成绩)

    (1)写一个SQL语句,查询选修了“计算机原理”的学生学号和姓名

    (2)写一个SQL语句,查询“小明”同学选修的课程名称

    (3)写一个SQL语句,查询选修了5门课程的学生学号和姓名

    答案:

    1

    select student.stu_no,student.stu_name

    from student,course,sc

    where course.c_no=sc.c_no and sc.stu_no=student.stu_no and course.c_name='计算机原理';

    2

    select course.c_name,student.stu_name

    from student,course,sc

    where student.stu_name='小明' and student.stu_no=sc.stu_no and sc.c_no=course.c_no;

    3

    select student.stu_no,stu_name

    from student,course,sc

    where student.stu_no=sc.stu_no and sc.c_no=course.c_no

    group by student.stu_no

    having count(*)=5

    建表及插入数据可参考如下语句:

    create table student(

    stu_no int,

    stu_name varchar(10),

    sex char(1),

    age int(3),

    edit varchar(20)

    );

    insert into student values

    (1,'wang','',21,'hello'),

    (2,'小明','',22,'haha2'),

    (3,'hu','',23,'haha3'),

    (4,'li','',25,'haha4');

    create table course(

    c_no int,

    c_name varchar(10)

    );

    insert into course values

    (1,'计算机原理'),

    (2,'java'),

    (3,'c'),

    (4,'php'),

    (5,'py');

    create table sc(

    sc_no int,

    stu_no int,

    c_no int,

    score int(3)

    );

    insert into sc values

    (1,1,1,80),

    (2,2,2,90),

    (3,2,1,85),

    (4,2,3,70),

    (5,2,4,95),

    (6,2,5,89);

  • 相关阅读:
    TextField 属性与注意
    as3:获取系统信息
    转:As3 优化总结,代码写法和api使用事项。
    文本编辑器制作(1):2种方案实现
    FlashBuilder编译参数
    as3 动态类库使用
    webgame:版本更新与本地缓存
    A*
    FlashBuilder方便的调试UI插件Monster Debugger
    sourcemate flex插件
  • 原文地址:https://www.cnblogs.com/reyinever/p/10134689.html
Copyright © 2011-2022 走看看