首页 > 数据库 >python: sql server

python: sql server

时间:2023-06-18 23:44:17浏览次数:46  
标签:StudentId python self ._ server CourseId sql go def

sql script:

/*
学生类:姓名、年龄、学号、成绩

班级类:班级名称、学生列表显示所有学生
根据学号查找学生
添加一个学生
删除一个学生(学生对象、学号)
根据学号升序排序
根据成绩降序排序

*/

--学生表
DROP TABLE StudentList
GO
create table StudentList
(
	 StudentId INT IDENTITY(1,1) PRIMARY KEY,
	 StudentName nvarchar(50),
	 StudentNO varchar(50),                    --学号
	 StudentBirthday datetime				   --学生生日
	 

)
go

insert into StudentList(StudentName,StudentNO,StudentBirthday) values(N'刘三','001','2007-12-27')
go
insert into StudentList(StudentName,StudentNO,StudentBirthday) values(N'王二','002','2008-2-14')
go

select * from StudentList
go


--课程名称
DROP TABLE Course
GO
create table Course
(
   CourseId INT IDENTITY(1,1) PRIMARY KEY,
   CourseName nvarchar(50)					--课程名称
)
go

insert into Course(CourseName) values(N'语文')
go
insert into Course(CourseName) values(N'英语')
go
insert into Course(CourseName) values(N'数学')
go

select * from Course
go




--班表名称
DROP TABLE GradeClass
GO
create table GradeClass
(
	ClassId INT IDENTITY(1,1) PRIMARY KEY,
	ClassName nvarchar(50)				--班级名称
)
go

insert into GradeClass(ClassName) values(N'二年级一班')
go

insert into GradeClass(ClassName) values(N'二年级二班')
go

select * from GradeClass
go



--成绩表
DROP TABLE StudentScore
GO
create table StudentScore
(
	 ScoreId INT IDENTITY(1,1) PRIMARY KEY,
	 StudentId int
		Foreign Key REFERENCES StudentList(StudentId),  --学生ID 外键
	 CourseId int
	    Foreign Key REFERENCES Course(CourseId),      --课程ID 外键
	 Score float									  --成绩
)
go

insert into StudentScore(StudentId,CourseId,Score) values(1,1,90)
insert into StudentScore(StudentId,CourseId,Score) values(1,2,56)
insert into StudentScore(StudentId,CourseId,Score) values(1,3,80)
go

insert into StudentScore(StudentId,CourseId,Score) values(2,1,92)
insert into StudentScore(StudentId,CourseId,Score) values(2,2,83)
insert into StudentScore(StudentId,CourseId,Score) values(2,3,78)
go

select * from StudentScore
go




---班级学生
DROP TABLE StudentClass
GO
create table StudentClass
(
	StudentClassId INT IDENTITY(1,1) PRIMARY KEY,
	StudentId int 
		Foreign Key REFERENCES StudentList(StudentId),   --学生ID 外键
	ClassId int 
		Foreign Key REFERENCES GradeClass(ClassId),		--班级ID 外键
)
go

insert into StudentClass(StudentId,ClassId) values(1,1)
go
insert into StudentClass(StudentId,ClassId) values(2,1)
go
select * from StudentClass
go

-- 成绩视图
select a.*,b.StudentNO,b.StudentName,b.StudentBirthday,c.CourseName from StudentScore as a--,as a,StudentList as b,Course as c StudentClass as d,GradeClass as f  
LEFT JOIN StudentList as b on a.StudentId=b.StudentId 
LEFT JOIN Course as c on a.CourseId =c.CourseId
LEFT JOIN StudentClass as d on d.StudentId=b.StudentId
go

-- 班级视图
select a.*,b.StudentNO,b.StudentNO,b.StudentName,d.ClassName from StudentClass as a
left join StudentList as b on a.StudentId=b.StudentId
left join GradeClass as d on a.ClassId=d.ClassId
go

  

"""
StudentListInfo.py
学生类
date 2023-06-16
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
"""

import datetime
import sys
import os

class StudentList(object):
    """
    学生类
    """
    def __init__(self,StudentName:str, StudentNO:str,StudentBirthday:datetime.datetime):
        self._StudentName=StudentName
        self._StudentNO=StudentNO
        self._StudentBirthday=StudentBirthday
        self._StudentId=0
        self._age=0

    def __del__(self):
        print(f"{self._StudentName}")

    def setStudentName(self,StudentName):
        self._StudentName=StudentName

    def getStudentName(self):
        return self._StudentName

    def setStudentNO(self,StudentNO):
        self._StudentNO=StudentNO

    def getStudentNO(self):
        return self._StudentNO

    def setStudentId(self,StudentId):
        self._StudentId=StudentId

    def getStudentId(self):
        return  self._StudentId

    def setStudentBirthday(self,StudentBirthday):
        self._StudentBirthday=StudentBirthday

    def setAge(self,age):
        self._age=age

    def getAge(self):
        return  self._age

    def __str__(self):
        return f"{self._StudentId},{self._StudentName},{self._StudentNO},{self._StudentBirthday}{self._age}"



"""
CourseInfo.py
课程类
date 2023-06-16
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
"""

class Course(object):
    """

    """

    def __init__(self,CourseName:str):
        self._CourseName=CourseName
        self._CourseId=0

    def __del__(self):
        print(f"{self._CourseName}")

    def setCourseId(self,CourseId):
        self._CourseId=CourseId

    def getCourseId(self):
        return self._CourseId

    def setCourseName(self,CourseName):
        self._CourseName=CourseName

    def getCourseName(self):
        return self._CourseName

    def __str__(self):
        return f"CourseId:{self._CourseId},CourseName:{self._CourseName}"

  

 

标签:StudentId,python,self,._,server,CourseId,sql,go,def
From: https://www.cnblogs.com/geovindu/p/17490035.html

相关文章

  • MySQL8(glibc2.28)二进制安装
    操作系统:centos7.9安装数据库:mysql-8.0.33-linux-glibc2.28一、升级gcc(传送阵:升级gcc)1、添加mysql8依赖库软连接mv/lib64/libstdc++.so.6/lib64/libstdc++.so.6_oldln-s/usr/local/gcc/lib64/libstdc++.so.6/lib64/libstdc++.so.62、查看GLIBC_2.28是否更新成功stri......
  • Python输出九九乘法表
    i=1;whilei<9:j=1;whilej<=i:print(f"{i}*{j}={i*j}\t",end='')j+=1;i+=1;print()......
  • 73.Mysql密码验证组件
    Mysql在设置用户密码时有一个关于密码验证组件,该组件的功能就是提高用户设置密码时的安全性。1.安装和卸载mysql>INSTALLCOMPONENT'file://component_validate_password';mysql>UNINSTALLCOMPONENT'file://component_validate_password';2.查看mysql>SHOWVARIABLE......
  • Python绘图使用subplots出现标题重叠的解决方法
    存在问题Matplotlib中subplot中绘制图形多图添加标题后易和坐标轴标注重叠,如图:解决方法方法1在plt.show之前添加plt.tight_layout()方法2在subplots中设置figsize参考https://blog.csdn.net/shizheng_Li/article/details/116047790......
  • SQL聚合/多表/连接查询
    一、聚合查询使用SQL自带的聚合函数进行查询,有count()、AVG()、min()、max()、sum()二、分组聚合查询SELECTCity,Gender,COUNT(*)FROMStudentsGROUPBYCity,Gender;三、多表查询    ......
  • SQL调优:让Java内存分担计算
    作者: 剽悍一小兔我们在工作中,经常会因为一条慢sql调半天。这一节,我给大家介绍一种提升查询效率的思路,那就是让Java内存帮我们分担一些运算。案例还是采用springBoot日记本系统,源码下载地址和教程在文末。先改一个BUG之前遗留了一个BUG需要我们解决,就是在日记的详情页,日记类型没......
  • 关于python反射机制中的参数问题处理
    关于python反射机制中的参数问题处理 python的反射机制十分的常用,主要是字符串与模块应用之间的连接方法。核心是将字符串转换成可以调用模块、模块方法的变量。主要包括了以下四个方法:hasattr(obj,name,/)Returnwhethertheobjecthasanattributewi......
  • SQL语句_链表(上)
    说到连表查询,我们先了解下别名。别名可以用在表上,也可以用在表中参数名。即 SELECT"表格别名"."表中参数名""表中参数别名"FROM“表格名” "表格别名" 或 SELECT"表格别名"."表中参数名"AS"表中参数别名"FROM“表格名”AS"表格别名" 举个例子 SELECTSI.st......
  • DataX在Windows上实现Mysql到Mysql同步数据以及配置多个job/多个表同步定时执行bat
    场景DataX-阿里开源离线同步工具在Windows上实现Sqlserver到Mysql全量同步和增量同步:DataX-阿里开源离线同步工具在Windows上实现Sqlserver到Mysql全量同步和增量同步_sqlserver数据同步工具_霸道流DataX-在Windows上实现postgresql同步数据到mysql:DataX-在Windows上实现postgres......
  • sql server 转移日志文件
    sqlserver转移日志文件要将SQLServer的日志文件转移到不同的位置,你可以按照以下步骤进行操作:1.首先,通过执行以下查询,获取当前数据库的日志文件的逻辑名称(LogicalName):  ```sql  USEYourDatabaseName;  SELECTname,physical_nameFROMsys.master_filesWHEREt......