zoukankan      html  css  js  c++  java
  • 连接查询和分组查询

    --查询年级所拥有的人数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)

  • 相关阅读:
    Poj 1742 Coins(多重背包)
    Poj 2350 Above Average(精度控制)
    求二进制数中1的个数
    Poj 1659 Distance on Chessboard(国际象棋的走子规则)
    Poj 2411 Mondriaan's Dream(压缩矩阵DP)
    Poj 2136 Vertical Histogram(打印垂直直方图)
    Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)
    poj 2390 Bank Interest(计算本利和)
    Poj 2533 Longest Ordered Subsequence(LIS)
    Poj 1887 Testing the CATCHER(LIS)
  • 原文地址:https://www.cnblogs.com/fkx1/p/7745250.html
Copyright © 2011-2022 走看看