• 连接查询和分组查询


    --查询年级所拥有的人数select GradeId as 年级,COUNT(Phone) as 人数 from Studentgroup by GradeId--根据性别进行分组select Sex as 性别,COUNT(*) as 人数 from Studentgroup by Sex--查询每门课程的平均分select SubjectId as 课程编号,AVG(StudentResult) as 平均分from Resultgroup by SubjectId--按地区分类,查询地区的人数select COUNT(*) as 人数,Address as 地址 from Studentgroup by Address--查询每门课程的平均分,并且按照分数由低到高的顺序排列显示select SubjectId as 课程编号,AVG(StudentResult) as 平均分 from Resultgroup by SubjectIdorder by AVG(StudentResult) desc--统计每学期男女同学的人数select COUNT(*) as 人数,GradeId as 年级,Sex as 性别 from StudentGroup by GradeId,Sexorder by GradeId--性别:男和女年级:1,2,3--如何获得总人数超过2人的年级select COUNT(*) as 人数,GradeId as 年级,Sex as 性别 from StudentGroup by GradeId,Sexhaving COUNT(*)>=2order by GradeId--出生日期大于1990年的学生,获得总人数超过2人的年级select COUNT(*) as 人数,GradeId as 年级,Sex as 性别 from Studentwhere BornDate >'1990/01/01'Group by GradeId,Sexhaving COUNT(*)>=2order by GradeId--同时从这两个表中取得数据select Student.StudentName as 姓名,Result.StudentResult as 成绩,Result.SubjectId AS 科目编号 from Student,Resultwhere Student.StudentNo=Result.StudentNo--内链接select S.StudentName as 姓名,R.StudentResult as 成绩,R.SubjectId AS 科目编号 from Result as Rinner join Student as S on(S.StudentNo=R.StudentNo)select S.StudentName as 姓名,R.StudentResult as 成绩,SU.SubjectName AS 科目名称 from Result as Rinner join Student as S on(S.StudentNo=R.StudentNo)inner join Subject as SU on(R.SubjectId=SU.SubjectId)select Student.StudentName as 姓名,Result.StudentResult as 成绩,Subject.SubjectName AS 科目名称 from Student,Result,Subjectwhere Student.StudentNo=Result.StudentNo and Result.SubjectId=Subject.SubjectId--左外连接select S.StudentName,R.SubjectId,R.StudentResult From Student AS SLEFT JOIN Result as Ron(S.StudentNo=R.StudentNo)--右外连接select S.StudentName,R.SubjectId,R.StudentResult From Result AS RRIGHT JOIN Student as Son(S.StudentNo=R.StudentNo)

  • 相关阅读:
    find 按文件修改时间查找文件
    Single- and Multichannel Memory Modes
    Jeff Dean Facts, Haha
    技巧:多共享动态库中同名对象重复析构问题的解决方法
    Processor technologies
    内存模型系列(上)- 内存一致性模型(Memory Consistency)
    python协程
    mysql学习笔记(1)
    python爬虫-----Python访问http的几种方式
    python基础 pyc
  • 原文地址:https://www.cnblogs.com/fkx1/p/7745250.html
Copyright © 2020-2023  润新知