zoukankan      html  css  js  c++  java
  • 数据库小练习

    Q1:20120007,
    SELECT
    stu_name,stu_gender,stu_birthday
    FROM
    t_student
    WHERE
    stu_id = 20127007
    
    Q2:会计1201,find student"s id & name
    SELECT
    a.stu_id,a.stu_name
    FROM
    t_student as a
    INNER JOIN t_class b ON b.cls_id = a.cls_id
    WHERE b.cls_name = '会计1201'
    
    Q3:会计,2012,find classes with students' couunt
    SELECT
    count(b.stu_id)
    FROM
    t_class a
    inner join t_student b ON b.cls_id = a.cls_id
    WHERE
    a.grade = 2012
    AND
        a.subject= '会计'
    第二种
    
    SELECT
    a.cls_name,
    count(*)
    FROM t_class a
    INNER JOIN t_student b ON a.cls_id = b.cls_id
    WHERE
    a.subject = '会计'
    AND
    a.grade = 2012
    GROUP BY
        a.cls_name
    
    Q4:20127007 find all failured course
    
    SELECT
    c.course_name
    FROM t_mark a
    INNER JOIN t_course c ON c.course_id = a.course_id
    
    WHERE
    a.stu_id = 20127001
    AND
    	 a.scroll < 60
    
    
    Q5:Add a new course,17317,'Course Foundation',3.5
    INSERT INTO t_course (
    course_id,course_name,course_credit)
    VALUES
        (17317,'DB Foundation',3.5)
    
    Q6:会计,2012,英语[1],FIND avg
    SELECT DISTINCT
    avg(c.scoll)
    FROM
    t_class a
    inner join t_student b ON b.cls_id = a.cls_id
    inner join t_mark c ON b.stu_id = c.stu_id
    inner join t_course d ON d.course_id = c.course_id
    WHERE
    a.grade = 2012
    AND
    a.subject = '会计'
    AND
    	 d.course_name = '英语[1]'
    
    Q7:会计,2012,英语[1],failure students
    SELECT DISTINCT
    b.*
    FROM
    t_class a
    inner join t_student b ON b.cls_id = a.cls_id
    inner join t_mark c ON b.stu_id = c.stu_id
    inner join t_course d ON d.course_id = c.course_id
    WHERE
    c.scroll < 60
    AND
    a.subject = '会计'
    AND
    	 d.course_name = '英语[1]'
    、方法2
    SELECT
    a.stu_name,b.cls_name
    FROM
    t_student a
    INNER JOIN t_class b ON a.cls_id=b.cls_id
    WHERE
    b.subject='会计'
    AND
    b.grade=2012
    AND
    EXISTS(
    SELECT 1 FROM t_mark c
    INNER JOIN t_course d ON d.course_id=c.course_id
    WHERE
    c.stu_id=a.stu_id
    AND
    d.course_name='英语[1]'
    AND
    c.scroll<60
    )
    
    Q8:会计,2012,5-course-failure
    SELECT DISTINCT
    b.stu_name/*按分组的列显示*/
    FROM
    t_class a
    inner join t_student b ON b.cls_id = a.cls_id
    inner join t_mark c ON b.stu_id = c.stu_id
    inner join t_course d ON d.course_id = c.course_id
    WHERE
    c.scroll < 60
    AND
    a.subject = '会计'
    AND
    a.grade =2012
    GROUP BY b.stu_name
    HAVING count(distinct c.course_id) >=5
    
    
    方法2
    SELECT DISTINCT
    b.stu_name,count(*),count(c.course_id)/*按分组的列显示*/
    FROM
    t_class a
    inner join t_student b ON b.cls_id = a.cls_id
    inner join t_mark c ON b.stu_id = c.stu_id
    inner join t_course d ON d.course_id = c.course_id
    WHERE
    c.scroll < 60
    AND
    a.subject = '会计'
    AND
    a.grade =2012
    GROUP BY b.stu_name
    HAVING count(distinct c.course_id) >=5
    
  • 相关阅读:
    Hibernate+JPA (EntityMange讲解)
    JPA和Hibernate的区别
    Hibernate与Jpa的关系,终于弄懂
    JEE学习线路
    J2EE中你必须了解的13种技术规范
    js设置datagriad的行移动
    js正则表达式中的特殊字符
    iOS 开发之动画篇
    Phone APP设计规范/iPad APP设计规范/Android APP设计规范/网页设计规范
    打包程序时的证书问题(上传APP就出现Missing iOS Distribution signing indetity for)
  • 原文地址:https://www.cnblogs.com/qianxinggz/p/10015499.html
Copyright © 2011-2022 走看看