头歌MySQL数据库实训答案有目录出色的你

数据库部分一条一条的写,可鼠标手动粘贴,除特定命令外未分大小写。第1关:创建数据库

mysql-uroot-p123123-h127.0.0.1createdatabaseMyDb;第2关创建表

mysql-uroot-p123123-h127.0.0.1createdatabaseTestDb;useTestDb;createtablet_emp(idint,namevarchar(32),deptIdint,salaryfloat);第3关:使用主键约束

mysql-uroot-p123123-h127.0.0.1createdatabaseMyDb;useMyDb;createtablet_user1(userIdINTPRIMARYKEY,nameVARCHAR(32),passwordVARCHAR(11),phoneVARCHAR(11),emailVARCHAR(32));createtablet_user2(nameVARCHAR(32),phoneVARCHAR(11),emailVARCHAR(32),PRIMARYKEY(name,phone));第4关:外键约束

mysql-uroot-p123123-h127.0.0.1createdatabaseMyDb;useMyDb;CREATETABLEt_class(idINTPRIMARYKEY,nameVARCHAR(22));)CREATETABLEt_student(idINTPRIMARYKEY,nameVARCHAR(22),classIdint,CONSTRAINTfk_stu_class1FOREIGNKEY(classId)REFERENCESt_class(id));第5关:添加常用约束

mysql-uroot-p123123-h127.0.0.1CREATEDATABASEMyDb;USEMyDb;CREATETABLEt_user(idINTPRIMARYKEYAUTO_INCREMENT,usernameVARCHAR(32)NOTNULLUNIQUE,sexVARCHAR(4)DEFAULT'男')DEFAULTCHARSET=utf8;MySQL数据库-数据库和表的基本操作(一)第1关:查看表结构与修改表名

USECompany;##########Begin####################modifythetablename##########ALTERTABLEtb_empRENAMEjd_emp;##########showtablesinthisdatabase##########showtables;##########describethetable##########describejd_emp;##########End##########第2关:修改字段名与字段数据类型

USECompany;#请在此处添加实现代码##########Begin####################changethecolumnname##########ALTERTABLEtb_empchangeIdprod_idint(11);##########changethedatatypeofcolumn##########ALTERTABLEtb_empMODIFYNamevarchar(30);##########End##########DESCRIBEtb_emp;第3关:添加与删除字段

USECompany;#请在此处添加实现代码##########Begin####################addthecolumn##########ALTERTABLEtb_empADDCountryvarchar(20)AFTERName;##########deletethecolumn##########ALTERTABLEtb_empDROPSalary;##########End##########DESCRIBEtb_emp;第4关:修改字段的排列位置

USECompany;#请在此处添加实现代码##########Begin####################modifythecolumntotop##########ALTERTABLEtb_empMODIFYNamevarchar(25)FIRST;##########modifythecolumntotherearofanothercolumn##########ALTERTABLEtb_empMODIFYDeptIdint(11)AFTERSalary;##########End##########DESCRIBEtb_emp;第5关:删除表的外键约束

USECompany;#请在此处添加实现代码##########Begin####################deletetheforeignkey##########ALTERTABLEtb_empDROPFOREIGNKEYemp_dept;##########End##########SHOWCREATETABLEtb_emp\G;MySQL数据库-数据库和表的基本操作(二)第1关:插入数据

USECompany;#请在此处添加实现代码##########Begin####################bundleinsertthevalue#########INSERTINTOtb_emp(Id,Name,DeptId,Salary)VALUES(1,"Nancy",301,2300.00),(2,"Tod",303,5600.00),(3,"Carly",301,3200.00);##########End##########SELECT*FROMtb_emp;##########End##########第2关:更新数据

USECompany;#请在此处添加实现代码##########Begin####################updatethevalue##########UPDATEtb_empSETName="Tracy",DeptId=302,Salary=4300.00WHEREid=3;##########End##########SELECT*FROMtb_emp;##########End##########DESCRIBEtb_emp;第3关:删除数据

USECompany;#请在此处添加实现代码##########Begin####################deletethevalue##########DELETEFROMtb_empWHERESalary>3000;##########End##########SELECT*FROMtb_emp;##########End##########DESCRIBEtb_emp;MySQL数据库-单表查询(一)第1关:基本查询语句

USECompany;#请在此处添加实现代码##########Begin####################retrievingtheNameandSalary##########selectName,Salaryfromtb_emp;##########retrievingallthetable##########select*fromtb_emp;##########End##########第2关:带IN关键字的查询

USECompany;#请在此处添加实现代码##########Begin####################retrievingtheNameandSalarywithINstatement##########SELECTName,SalaryFROMtb_empWHEREIdNOTIN(1);##########End##########第3关:带BETWEENAND的范围查询

USECompany;#请在此处添加实现代码##########Begin####################retrievingtheNameandSalarywithBETWEENANDstatement##########SELECTName,SalaryFROMtb_empWHERESalaryBETWEEN3000AND5000;##########End##########MySQL数据库-单表查询(二)第1关:带LIKE的字符匹配查询

USECompany;#########Begin#########SELECTName,SalaryFROMtb_empWHERENameLIKE"C%";#########End#########第2关:查询空值与去除重复结果

USECompany;#########Begin#########SELECT*FROMtb_empWHEREDeptIdISNULL;#########End##################Begin#########SELECTDISTINCTNameFROMtb_emp;#########End#########第3关:带AND与OR的多条件查询

USECompany;#########Begin#########SELECT*FROMtb_empWHEREDeptId=301ANDSalary>3000;#########End##################Begin#########SELECT*FROMtb_empWHEREDeptId=301ORDeptId=303;#########End#########MySQL数据库-单表查询(三)第1关:对查询结果进行排序

USESchool;#请在此处添加实现代码##########Begin####################查询1班同学的所有信息以成绩降序的方式显示结果##########select*fromtb_scorewhereclass_id=1orderbyscoredesc;##########End##########第2关:分组查询

USESchool;#请在此处添加实现代码##########Begin####################对班级名称进行分组查询##########SELECT*FROMtb_classGROUPBYclass_id;##########End##########第3关:使用LIMIT限制查询结果的数量

USESchool;#请在此处添加实现代码##########Begin####################查询班级中第2名到第5名的学生信息##########SELECT*FROMtb_scoreorderbyscoredescLIMIT1,4;##########End##########MySQL数据库-连接查询第1关:内连接查询

USESchool;##########查询数据表中学生姓名和对应的班级###########请在此处添加实现代码##########Begin##########selecttb_student.nameasstudentName,tb_class.nameasclassNamefromtb_studentjointb_classontb_class.id=tb_student.class_id;##########End##########第2关:外连接查询

USESchool;##########使用左外连接查询所有学生姓名和对应的班级###########请在此处添加实现代码##########Begin##########selecttb_student.nameasstudentName,tb_class.nameasclassNamefromtb_classrightjointb_studentontb_class.id=tb_student.class_id;##########End####################使用右外连接查询所有学生姓名和对应的班级##########selecttb_student.nameasstudentName,tb_class.nameasclassNamefromtb_classleftjointb_studentontb_class.id=tb_student.class_id;#请在此处添加实现代码##########Begin####################End##########第3关:复合条件连接查询

USESchool;##########查询所有班级里分数在90分以上的学生的姓名和学生的成绩以及学生所在的班级###########请在此处添加实现代码##########Begin##########selects1.nameasstudentName,score,s2.nameasclassNamefromtb_studentass1,tb_classass2wheres1.class_id=s2.idands1.score>90orderbyscoredesc;##########End##########MySQL数据库-子查询第1关:带比较运算符的子查询

USECompany;#请在此处添加实现代码##########Begin###########1.查询大于所有平均年龄的员工姓名与年龄selectname,agefromtb_empwhereage>(selectavg(age)fromtb_emp);##########End##########第2关:关键字子查询

USECompany;#请在此处添加实现代码##########Begin###########1.使用ALL关键字进行查询SELECTposition,salaryFROMtb_salaryWHEREsalary>ANY(SELECTmax(salary)FROMtb_salarywhereposition="java");#2.使用ANY关键字进行查询SELECTposition,salaryFROMtb_salaryWHEREsalary>ANY(SELECTmin(salary)fromtb_salarywhereposition="java");#3.使用IN关键字进行查询selectposition,salaryfromtb_salarywherepositionin("java");##########End##########MySQL数据库-复杂查询(一)第1关:交换工资

#请在此添加实现代码##########Begin##########UPDATEtb_SalarySETsex=CASEsexWHEN"m"THEN"f"ELSE"m"END;##########End##########第2关:换座位

#请在此添加实现代码##########Begin##########SELECTif(Id%2=0,Id-1,if(Id=5,Id,Id+1))ASid,nameFROMtb_SeatORDERBYId;##########End##########第3关:分数排名

#请在此添加实现代码##########Begin##########selectScore,(selectcount(distinctscore)fromscorewherescore>=s.score)asRankfromscoreassorderbyScoredesc;selectScore,(selectcount(*)fromscoreass2wheres2.score>s1.score)+1asRankfromscoreass1orderbyRank;##########End##########第4关:体育馆的人流量

#请在此添加实现代码##########Begin##########selectdistincta.*fromgymnasiuma,gymnasiumb,gymnasiumcwherea.visitors_flow>=100andb.visitors_flow>=100andc.visitors_flow>=100and((a.id=b.id-1andb.id=c.id-1)or(a.id=b.id-1anda.id=c.id+1)or(a.id=b.id+1andb.id=c.id+1))orderbya.id;##########End##########第5关:统计总成绩

#请在此添加实现代码##########Begin##########selectt1.classname,t1.chinese,t2.mathsfrom(selectc.classnameclassname,sum(s.chinese)chinesefromtb_classc,tb_scoreswherec.stuname=s.nameands.chinese>=60groupbyc.classname)t1,(selectc.classnameclassname,sum(s.maths)mathsfromtb_classc,tb_scoreswherec.stuname=s.nameands.maths>=60groupbyc.classname)t2wheret1.classname=t2.classname;##########End##########MySQL数据库-复杂查询(二)第1关:查询学生平均分

#请在此添加实现代码##########Begin##########selectb.s_id,b.s_name,ROUND(AVG(a.s_score),2)asavg_scorefromstudentbinnerjoinscoreaonb.s_id=a.s_idGROUPBYb.s_id,b.s_nameHAVINGavg_score<60unionselecta.s_id,a.s_name,0asavg_scorefromstudentawherea.s_idnotin(selectdistincts_idfromscore);##########End##########第2关:查询修课相同学生信息

#请在此添加实现代码##########Begin##########createviewtempas(selects_id,group_concat(c_id)ascfromscoregroupbys_id);select*fromstudentwheres_idin(selects_idfromtempwherec=(selectcfromtempwheres_id="01")ands_id<>"01");##########End##########第3关:查询各科成绩并排序

#请在此添加实现代码##########Begin##########selecta.*,count(b.s_score)+1rankfromscorealeftjoinscorebona.c_id=b.c_idanda.s_score

#请在此添加实现代码##########Begin##########selecta.*,b.s_score,b.c_id,c.c_namefromstudentaINNERJOINscorebONa.s_id=b.s_idINNERJOINcoursecONb.c_id=c.c_idwhereb.c_id=(selectc_idfromcoursec,teacherdwherec.t_id=d.t_idandd.t_name="张三")andb.s_scorein(selectMAX(s_score)fromscorewherec_id="02");##########End##########第5关:查询两门课程不及格同学信息

#请在此添加实现代码##########Begin##########selecta.s_id,a.s_name,ROUND(AVG(b.s_score))avg_scorefromstudentainnerjoinscorebona.s_id=b.s_idwherea.s_idin(selects_idfromscorewheres_score<60GROUPBYs_idhavingcount(*)>=2)GROUPBYa.s_id,a.s_name;##########End##########MySQL数据库-使用聚合函数查询第1关:COUNT()函数

USESchool;#请在此处添加实现代码##########Begin####################查询该表中一共有多少条数据##########selectcount(*)fromtb_class;##########查询此表中367班有多少位学生##########selectclassid,count(*)fromtb_classwhereclassid=367;##########End##########第2关:SUM()函数

USESchool;#请在此处添加实现代码##########Begin####################查询所有学生总分数##########selectsum(score)fromtb_class;##########查询学生语文科目的总分数##########selectcourse,sum(score)fromtb_classwherecourse="语文";##########End##########第3关:AVG()函数

USESchool;#请在此处添加实现代码##########Begin####################查询学生语文科目的平均分数##########selectcourse,avg(score)fromtb_classwherecourse="语文";##########查询学生英语科目的平均分数##########selectcourse,avg(score)fromtb_classwherecourse="英语";##########End##########第4关:MAX()函数

USESchool;#请在此处添加实现代码##########Begin####################查询语文课程中的最高分数##########selectcourse,max(score)fromtb_classwherecourse="语文";##########查询英语课程中的最高分数##########selectcourse,max(score)fromtb_classwherecourse="英语";##########End##########第5关:MIN()函数

USESchool;#请在此处添加实现代码##########Begin####################查询语文课程中的最低分数##########selectcourse,min(score)fromtb_classwherecourse="语文";##########查询英语课程中的最低分数##########selectcourse,min(score)fromtb_classwherecourse="英语";##########End##########MySQL数据库-其他函数的使用第1关:字符函数

#请在此添加实现代码##########Begin##########selectCONCAT(UPPER(SUBSTR(Name,1,1)),LOWER(SUBSTR(Name,2,LENGTH(Name))))asNamefromemployee;##########End##########第2关:数学函数

#请在此添加实现代码##########Begin####################查询学生出生年份及年龄##########selectyear(s_birth)year,'2019-01-01'-s_birth'年龄'fromStudent;##########查询课程的最高分、最低分、平均分和及格率#########selectc.c_id'课程id',c_name'课程名',max(s_score)'最高分',min(s_score)'最低分',round(avg(s_score),2)'平均分',round((count(s_score>=60ornull)/count(s_score))*100,2)'及格率'fromScores,Coursecwheres.c_id=c.c_idgroupbys.c_id;##########End##########第4关:自定义函数

#请在此添加实现代码##########Begin##########delimiter//createfunctionfn_three_max(param_1int,param_2int,param_3int)RETURNSintBEGINDECLAREmax_valintDEFAULT0;ifparam_1>param_2thensetmax_val=param_1;elsesetmax_val=param_2;endif;ifparam_3>max_valthensetmax_val=param_3;endif;returnmax_val;END//##########End##########MySQL数据库-分组选择数据第1关:GROUPBY与聚合函数

USESchool;#请在此处添加实现代码##########Begin###########1.查询表中2,3,4年级中分别男女的总人数selectgradeId,sex,count(*)fromstudentwheregradeIdin(2,3,4)groupbygradeId,sex;##########End##########第2关:使用HAVING与ORDERBY

USESchool;#请在此处添加实现代码##########Begin###########1.查询表中至少有两门课程在90分以上的学生信息selectsno,count(*)fromtb_gradewherescore>=90groupbysnohavingcount(pno)>=2;#2.查询表中平均成绩大于90分且语文课在95分以上的学生信息selectsno,avg(score)fromtb_gradewheresnoin(selectsnofromtb_gradewherescore>=95andpno="语文")groupbysnohavingavg(score)>=90;##########End##########数据库2-MySQL数据管理技术实战MySQL开发技巧-视图第1关:视图

useSchool;#请在此处添加实现代码##########Begin###########1.创建单表视图CREATEVIEWstu_viewASselectmath,chinese,math+chineseFROMstudent;#2.创建多表视图CREATEVIEWstu_classesASselectstudent.stu_id,student.name,stu_info.classesFROMstudent,stu_infoWHEREstudent.stu_id=stu_info.stu_id;##########End##########MySQL开发技巧-索引第1关:索引

useSchool;#请在此处添加实现代码##########Begin###########1.创建名为pk_student的主键索引createtablestudent(stu_idintnotnull,namevarchar(25)notnull,ageintnotnull,sexchar(2)notnull,classesintnotnull,gradeintnotnull,primarykey(stu_id));#2.创建名为idx_age的普通索引createindexidx_ageonstudent(age);#3.创建名为uniq_classes的唯一索引createuniqueindexuniq_classesonstudent(classes);#4.创建名为idx_group的组合索引altertablestudentaddindexidx_group(name,sex,grade);##########End##########MySQL开发技巧-分页和索引第1关:MySQL分页查询

USEProducts;#请在此处添加实现代码##########Begin###########1.分页查询selectprod_idfromproductswhereprod_id>(selectprod_idfromproductslimit4,1)limit5;#2.用子查询优化分页查询语句selectprod_idfromproductswhereprod_id>(selectprod_idfromproductslimit9,1)limit5;##########End##########第2关:索引(单列索引)

USEStudents;#请在此处添加实现代码##########Begin###########1.创建student表结构并且设置id为主键索引CREATETABLEstudent(idint(11)NOTNULLAUTO_INCREMENT,namevarchar(20)NOTNULL,scoreint(10),PRIMARYKEY(id));#2.对name建立唯一索引CREATEUNIQUEINDEXname_indexON`student`(`name`);#3.对score建立普通索引CREATEINDEXscore_indexON`student`(`score`);SHOWINDEXFROMstudent;##########End##########第3关:索引(组合索引)

USEPerson;#请在此处添加实现代码##########Begin###########1.增加组合索引ALTERTABLEpersonADDINDEXname_city_score(name,age,address);##########End##########SHOWINDEXFROMperson;MySQL开发技巧-存储过程第1关:存储过程

USEmydb;#请在此处添加实现代码##########Begin##########dropprocedureifexistsmydb.GetCustomerLevel;delimiter$$createPROCEDUREGetCustomerLevel(inp_customNumberint(11),outp_customerLevelvarchar(10))Begindeclarelevelsint;selectcreditlimitintolevelsfromcustomerswherecustomerNumber=p_customNumber;iflevels<5000thensetp_customerLevel='SILVER';elseiflevels<10000thensetp_customerLevel='GOLD';elsesetp_customerLevel='PLATINUM';endif;selectp_customNumberascustomerNumber,p_customerLevel;End$$delimiter;##########End##########MySQL开发技巧-事务第1关:事务

USEmydb;#请在此处添加实现代码##########Begin###########修改存储过程————向t_emp表中插入数据(注意请勿修改提供的代码框架)dropprocedureifexistsmydb.proc_insert;delimiter$$createprocedureproc_insert()Begin #开启事务 starttransaction;insertintot_empvalues(1,'Nancy',301,2300);insertintot_empvalues(2,'Tod',303,5600); insertintot_empvalues(3,'Carly',301,3200); #事务提交 commit;END$$delimiter;##########End##########MySQL开发技巧-并发控制第1关:表锁

useSchool;#请在此处添加实现代码##########Begin##########insertintostudentvalues(1,'Tom',80,78);insertintostudentvalues(3,'Lucy',97,95);locktablestudentread;updatestudentsetmath=100wherestu_id=2;##########End##########第2关:事务隔离级别

usemydb;#请在此处添加实现代码##########Begin###########1.修改隔离级别setsessiontransactionisolationlevelReaduncommitted;#2.查询隔离级别select@@tx_isolation;##########End##########第3关:行锁

mysql-uroot-p123123-h127.0.0.1source/data/workspace/myshixun/src/step3/table.sql;begin;select*fromaccountforupdate;updateaccountsetmoney=0wherename='A';updateaccountsetmoney=0wherename='B';commit;MySQL开发技巧-行列转换第1关:使用CASE语句实现行转列

#请在此添加实现代码##########Begin##########selects_name,SUM(casec_namewhen'语文'thens_scoreend)'语文',SUM(casec_namewhen'数学'thens_scoreend)'数学',SUM(casec_namewhen'英语'thens_scoreend)'英语'fromscoregroupbys_name;##########End##########第2关:序列化表的方法实现列转行(一)

#请在此添加实现代码##########Begin##########selectb.name,substring_index(replace(substring(substring_index(b.scores,',',s.id),char_length(substring_index(b.scores,',',s.id-1))+1),',',''),':',1)course,substring_index(replace(substring(substring_index(b.scores,',',s.id),char_length(substring_index(b.scores,',',s.id-1))+1),',',''),':',-1)scorefromtb_sequencesinnerjoin(selectname,scoresascourse,scores,length(scores)-length(replace(scores,',',''))+1sizefromtb_score)bons.id<=b.size;##########End##########第3关:序列化表的方法实现列转行(二)

#请在此添加实现代码##########Begin##########selects_name,casewhens.id=1then'语文'whens.id=2then'数学'whens.id=3then'英语'ends_cource,coalesce(casewhens.id=1thenchineseend,casewhens.id=2thenmathend,casewhens.id=3thenenglishend)s_scorefromtb_scoretinnerjointb_sequenceswheres.id<=3orderbys_name,field(s_cource,'数学','英语','语文');##########End##########MySQL开发技巧-删除重复数据第1关:利用主键删除

#请在此添加实现代码##########Begin##########deletefromuserswhereidin(select*from(selectidfromuserswhereuser_namein(selectuser_namefromusersgroupbyuser_namehavingcount(1)>1)andidnotin(selectmin(id)fromusersgroupbyuser_namehavingcount(1)>1))asstu_repeat_copy);##########End##########第2关:复杂重复数据删除

#请在此添加实现代码##########Begin##########updateusersbjoin(selectuser_name,group_concat(distinctSUBSTRING_INDEX(SUBSTRING_INDEX(mobile,',',t.id),',',-1))mobilefrom(selectuser_name,mobile,length(concat(mobile,','))-length(replace(mobile,',',''))sizefromusers)ainnerjointb_sequencetona.size>=t.idgroupbya.user_name)conb.user_name=c.user_namesetb.mobile=c.mobile;##########End##########MySQL开发技巧-批量数据入库及检索第1关:MySQL数据库连接

#coding=utf-8importpymysqldefconnect():#请在下面添加连接数据库的代码,完成相应功能#######Begin######conn=pymysql.connect(host='localhost',user='root',passwd='123123',charset='utf8')#######End##############请不要修改以下代码#######returnconn.get_host_info()第2关:数据库与数据表创建

#coding=utf-8#连接数据库,建立游标cursorimportpymysqldefcreate():conn=pymysql.connect(host='localhost',user='root',passwd='123123',charset='utf8')cursor=conn.cursor()#-----------Begin----------#创建enroll数据库cursor.execute('createdatabaseenroll')conn.select_db('enroll')#创建nudt数据表cursor.execute('createtablenudt(yearint,provincevarchar(100),firstBatchint)')#------------End-----------第3关:批量数据入库与检索

//请在下面补齐查询一的MySQL语句/*********begin*********/selectename,eid,sexfromempwheredidin(selectdidfromdeptwheredname='cwb')/*********end*********/andbirth<=all(selectbirthfromempwheredidin(selectdidfromdeptwheredname='yfb'));//请在下面输入查询二的MySQL语句/*********begin*********/selectename,income,outcomefromemp,sal,deptwhereemp.eid=sal.eidandemp.did=dept.didanddname='cwb'andincome>5200;/*********end*********/第2关:深入学习查询语句

//请在下面输入查询一的MySQL语句/*********begin*********/selectcount(eid)fromempwheredid=(selectdidfromdeptwheredname='cwb');/*********end*********///请在下面输入查询二的MySQL语句/*********begin*********/selectcount(eid)fromempgroupbydid;/*********end*********///请在下面输入查询三的MySQL语句/*********begin*********/selectemp.enamefromemp,salwhereemp.eid=sal.eidorderbyincome;/*********end*********/第3关:视图的创建和使用

//请在下面输入创建cx_sal的视图的MySQL语句/*********begin*********/createorreplaceviewcx_salasselectename,income,outcomefromemp,sal,deptwhereemp.eid=sal.eidandemp.did=dept.didanddname='cwb';/*********end*********///请在下面输入查询财务部雇员薪水情况视图的MySQL语句/*********begin*********/select*fromcx_sal;/*********end*********/第4关:索引与完整性

//请在下面输入创建索引的MySQL语句/*********begin*********/createindexpk_xs_bakonemp(eid);/*********end*********///请在下面输入实现域完整性的MySQL语句/*********begin*********/altertableempadd(constraintch_telcheck(telbetween0and9));/*********end*********///请在下面输入实现实体完整性的MySQL语句/*********begin*********/altertabledeptaddconstraintun_deptunique(dname);/*********end*********///请在下面输入实现参照完整性的MySQL语句/*********begin*********/altertableempaddconstraintsal_idforeignkey(eid)referencessal(eid);/*********end*********/数据库查询-选课系统第1关:数据库数据的插入

#*********Begin*********#echo"selectSname,SdeptfromstudentwhereSdept='计算机系';selectSnofromdbscwhereGrade<60;selectSname,Sdept,SagefromstudentwhereSage>=20andSage<=23andSdept='信息系';selectSno,GradefromdbscwhereCno='c02'orderbyGradedesc;selectcount(*)fromstudent;"#*********End*********#第3关:进阶查询

#*********Begin*********#echo"selectstudent.*fromstudentwhereSnamelike'张%';selectSname,Ssex,SdeptfromstudentwhereSdeptin('计算机系','信息系','数学系');selectCno,count(*)fromdbscwhereisTec='选修'groupbyCno;selectSnofromdbscgroupbySnohavingcount(*)>3;selectSname,Cno,Gradefromdbscleftjoinstudentonstudent.Sno=dbsc.Snowherestudent.Sdept='计算机系';"#*********End*********#第4关:复杂查询

#*********Begin*********#echo"selectdistinctdbsc.Sno,student.Snamefromdbscjoinstudentonstudent.Sno=dbsc.Snowheredbsc.isTec='选修';selectSname,count(*),avg(Grade)fromdbscjoinstudentonstudent.Sno=dbsc.Snogroupbydbsc.Sno;selectavg(Grade),count(*)fromdbscjoinstudentonstudent.Sno=dbsc.Snogroupbydbsc.Snohavingcount(*)>=4;selectstudent.Sname,dbsc.Cno,dbsc.Gradefromstudentleftjoindbsconstudent.Sno=dbsc.Snowherestudent.Sdept='信息系'anddbsc.isTec='选修'andCno='C02';updatedbscsetGrade=Grade+5whereGrade<60;"#*********End*********#数据库设计-博客系统第1关:数据库表设计-用户信息表

classConfig(object):#连接数据库######Begin######SQLALCHEMY_DATABASE_URI="mysql+pymysql://root:123123@localhost:3306/web"SQLALCHEMY_TRACK_MODIFICATIONS=True######End######step1/models.py

fromappimportdbclassMessage(db.Model):#表模型#*********Begin*********#id=db.Column(db.Integer,primary_key=True)ct=db.Column(db.Integer)provincename=db.Column(db.String(255))cityname=db.Column(db.String(255))#*********End*********#step1/test.py

fromappimportdb,appfrommodelsimportMessagefromflaskimportrender_template@app.route("/select")defselect():#*********Begin*********#pro=Message.query.order_by(Message.ct.desc()).all()city=list(map(lambdax:x.cityname,pro))count=list(map(lambdax:x.ct,pro))province=list(map(lambdax:x.provincename,pro))#*********End*********#returnrender_template("index.html",city=city,count=count,province=province)@app.route("/")defhome():returnrender_template("home.html")if__name__=="__main__":app.run(debug=True,host='0.0.0.0',port=8080)第2关:增加操作step2/config.py

classConfig(object):#连接数据库######Begin######SQLALCHEMY_DATABASE_URI="mysql+pymysql://root:123123@localhost:3306/webcharset=utf8"SQLALCHEMY_TRACK_MODIFICATIONS=True######End######step2/models.py

fromappimportdbclassMessage(db.Model):#表模型######Begin######id=db.Column(db.Integer,primary_key=True)ct=db.Column(db.Integer)provincename=db.Column(db.String(255))cityname=db.Column(db.String(255))######End######step2/test.py

fromappimportapp,dbfrommodelsimportMessagefromflaskimportFlask,render_template,request,redirect@app.route('/insert',methods=['GET','POST'])definsert():#进行添加操作#*********Begin*********#province=request.form['province']city=request.form['city']number=request.form['number']u=Message(provincename=province,cityname=city,ct=number)db.session.add(u)db.session.commit()#*********End*********#returnredirect('/')@app.route("/insert_page")definsert_page():#跳转至添加页面returnrender_template("insert.html")@app.route("/")defhome():listCity=Message.query.order_by(Message.id.desc()).all()returnrender_template("home.html",city_list=listCity)if__name__=="__main__":app.run(debug=True,host="0.0.0.0",port=8080)第3关:删除操作step3/test.py

fromappimportdb,appfrommodelsimportMessagefromflaskimportrender_template,redirect,request@app.route("/delete",methods=['GET'])defdelete():#操作数据库得到目标数据,before_number表示删除之前的数量,after_name表示删除之后的数量#*********Begin*********#id=request.args.get("id")message=Message.query.filter_by(id=id).first()db.session.delete(message)db.session.commit()#*********End*********#returnredirect('/')@app.route("/")defhome():listCity=Message.query.order_by(Message.id.desc()).all()returnrender_template("home.html",city_list=listCity)if__name__=="__main__":app.run(debug=True,host="0.0.0.0",port=8080)step3/config.py

classConfig(object):#连接数据库######Begin######SQLALCHEMY_DATABASE_URI="mysql+pymysql://root:123123@localhost:3306/webcharset=utf8"SQLALCHEMY_TRACK_MODIFICATIONS=True######End######step3/models.py

fromappimportdbclassMessage(db.Model):#表模型#*********Begin*********#id=db.Column(db.Integer,primary_key=True)ct=db.Column(db.Integer)provincename=db.Column(db.String(255))cityname=db.Column(db.String(255))#*********End*********#第4关:修改操作

fromtaskimportentry_FormclassTest():defselect_Table(self):#请在此处填写代码,并根据左侧编程要求完成本关考核#**********Begin*********#ap=entry_Form()pro=ap.query.filter(entry_Form.company_name=="阿里",entry_Form.eduLevel_name=="硕士",entry_Form.salary>=20000,entry_Form.salary<=25000,entry_Form.Entry_time>="2019-06").all()returnpro#**********End**********#第3关:添加操作

importpandasaspdfromtaskimportdb,entry_FormclassMessage:defupdate_table(self):#请根据左侧编程要求完成相应的代码填写#文件路径为"data.csv"模型类(已实现):entry_Form#数据库表已创建只需要完成添加操作即可#**********Begin*********#data=pd.read_csv(r"data.csv",encoding="utf8",sep="\t")list=[]forindex,rowindata.iterrows():user_info=entry_Form(ID=row['ID'],company_name=row['company_name'],eduLevel_name=row['eduLevel_name'],Entry_time=row['Entry_time'],jobName=row['jobName'],salary=row['salary'])list.append(user_info)#添加多条数据db.session.add_all(list)##db.session.add(data2)db.session.commit()#**********End**********#第4关:删除操作

fromoperatorimportor_fromtaskimportdb,entry_FormclassDemo:defdel_col(self):#请在此处填写代码,根据左侧编程要求完成数据的批量删除#**********Begin*********#user_info=entry_Form()user_info.query.filter(entry_Form.company_name=="华为",or_(entry_Form.jobName=="Java工程师",entry_Form.jobName=="Python工程师")).delete()db.session.commit()#**********End**********#第5关:修改操作

#请在此添加实现代码##########Begin###########在warehouse_db库中创建warehouse表usewarehouse_db;CREATETABLE`warehouse`(`warehouseId`int(11)NOTNULL,`area`int(11)NOTNULL,`phone`int(11)NOTNULL,PRIMARYKEY(`warehouseId`));#在warehouse_db库中创建component表CREATETABLE`component`(`componentId`int(11)NOTNULL,`componentName`varchar(20)NOTNULL,`standard`varchar(255)NOTNULL,`price`double(10,2)NOTNULL,`describe`varchar(255)NOTNULL,PRIMARYKEY(`componentId`));#在warehouse_db库中创建supplier表CREATETABLE`supplier`(`supplyId`int(11)NOTNULL,`name`varchar(20)NOTNULL,`address`varchar(255)NOTNULL,`phone`int(11)NOTNULL,`account`bigint(18)NOTNULL,PRIMARYKEY(`supplyId`));##########End##########第2关:数据库表设计-项目职员表

#请在此添加实现代码##########Begin###########在warehouse_db库中创建project表usewarehouse_db;CREATETABLE`project`(`projectId`int(11)NOTNULL,`projectBudget`double(10,0)NOTNULL,`commenceDate`datetimeNOTNULL,PRIMARYKEY(`projectId`));#在warehouse_db库中创建employee表CREATETABLE`employee`(`employeeId`int(11)NOTNULL,`name`varchar(20)NOTNULL,`age`int(3)NOTNULL,`designation`varchar(20)NOTNULL,`warehouseId`int(11)NOTNULL,`leaders`varchar(20)NOTNULL,PRIMARYKEY(`employeeId`),INDEX`FK_employee_warehouseId`(`warehouseId`),CONSTRAINT`FK_employee_warehouseId`FOREIGNKEY(`warehouseId`)REFERENCES`warehouse`(`warehouseId`));##########End##########第3关:数据库表设计-关联表

#请在此添加实现代码##########Begin###########在library_db库中创建books表uselibrary_db;CREATETABLE`books`(`bookId`int(11)NOTNULL,`bookName`varchar(255)NOTNULL,`publicationDate`datetimeNOTNULL,`publisher`varchar(255)NOTNULL,`bookrackId`int(11)NOTNULL,`roomId`int(11)NOTNULL,PRIMARYKEY(`bookId`));##########End##########第2关:数据库表设计-读者表

#请在此添加实现代码##########Begin###########在library_db库中创建reader表uselibrary_db;CREATETABLE`reader`(`borrowBookId`int(11)NOTNULL,`name`varchar(20)NOTNULL,`age`int(11)NOTNULL,`sex`varchar(2)NOTNULL,`address`varchar(255)NOTNULL,PRIMARYKEY(`borrowBookId`));##########End##########第3关:数据库表设计-关联表

#请在此添加实现代码##########Begin###########在library_db库中创建bookrack表uselibrary_db;CREATETABLE`bookrack`(`bookrackId`int(11)NOTNULL,`roomId`int(11)NOTNULL,PRIMARYKEY(`bookrackId`)USINGBTREE,INDEX`FK_bookrack_roomId`(`roomId`)USINGBTREE,CONSTRAINT`FK_bookrack_bookrackId`FOREIGNKEY(`bookrackId`)REFERENCES`books`(`bookrackId`),CONSTRAINT`FK_bookrack_roomId`FOREIGNKEY(`roomId`)REFERENCES`books`(`roomId`));#在library_db库中创建borrow表CREATETABLE`borrow`(`borrowBookId`int(11)NOTNULL,`bookId`int(11)NOTNULL,`borrowDate`datetimeNOTNULL,`returnDate`datetimeNOTNULL,PRIMARYKEY(`borrowBookId`)USINGBTREE,KEY`FK_borrow_borrowBookId`(`borrowBookId`),KEY`FK_borrow_bookId`(`bookId`),CONSTRAINT`FK_borrow_borrowBookId`FOREIGNKEY(`borrowBookId`)REFERENCES`reader`(`borrowBookId`),CONSTRAINT`FK_borrow_bookId`FOREIGNKEY(`bookId`)REFERENCES`books`(`bookId`));##########End##########

THE END
1.Python头歌实验题目(2024版)头歌实践平台免费答案武汉理工大学 python头歌平台实验题目答案 第1关 欢迎入学 a=input() print('|++++++++++++|') print('| |') print('| Welcome to WHUT |') print('| |') print('|++++++++++++|') print(f'欢迎您,{a}同学!') 第2关 整数四则运算 a=int(inputhttps://blog.csdn.net/2401_84152595/article/details/139385025
2.头歌实践教学平台python模块的构建与使用的答案头歌educoder实训头歌实践教学平台python模块的构建与使用的答案 头歌educoder实训作业答案递归,1.若有以下程序:#include<stdio.h>#defineSUB(X,Y)(X+1)*Yintmain(){inta=3,b=4;printf("%d\n",SUB(a++,b++));return0;}程序运行的结果是?A.25B.20C.12D.16答案:D.16,后置++,先使用https://blog.51cto.com/u_16213629/11436432
3.头歌实践教学平台python的几种数据结构列表及操作答案.docx该【头歌实践教学平台python的几种数据结构列表及操作答案】是由【鼠标】上传分享,文档一共【1】页,该文档可以免费在线阅读,需要了解更多关于【头歌实践教学平台python的几种数据结构列表及操作答案】的内容,可以使用淘豆网的站内搜索功能,选择自己适合的文档,以下文https://www.taodocs.com/p-919562007.html
4.头歌实践平台(Educoder):python教学案例三字符类型及其操作第1关 提取身份证号性别 sfzh=input("输入身份证号") #代码开始 sex = sfzh[:17] sex = int(sex) if sex % 2 == 0: print("https://www.iotword.com/29260.html
5.头歌实践教学平台Pythonscore_avg = add_avg(score_lst_f) print(sorted(score_avg, key=lambda x: (x[-1],-x[-2]),reverse=True)[:n]) 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明vb.net教程C#教程python教程。 原文链接:https://www.360doc.cn/article/21609410_1121838564.html
6.头歌实践教学平台(EduCoder)是信息技术类实践教学平台。(EduCoder)涵盖了计算机、大数据、云计算、人工智能、软件工程、物联网等专业课程。超60000个实训案例,建立学、练、评、测一体化实验环境。https://www.educoder.net/forums/4764
7.头歌Python答案及解析+C语言答案2024合集PDF版电子书下载应用平台:PDF 更新时间:2024-07-11 购买链接:京东异步社区 网友评分: 360通过腾讯通过金山通过 3.9MB 详情介绍 头歌Python程序答案/C语言答案是一份集合了Python、C语言编程学习中的各类问题解答的资源,主要针对初学者和进阶者在学习过程中遇到的难题提供解决方案。这份压缩包可能包含了课后习题、项目实践以及编程挑战https://www.jb51.net/books/944642.html
8.头歌python入门之基础语法答案.docx头歌python入门之基础语法答案单选题(每题2分,共30题) 1.保存文件的快捷键() [单选题] * Ctrl+V Ctrl+C Ctrl+S(正确答案) Ctrl+N 5.以下不是Python的数值型数据() [单选题] * A.-10 B.10+5j C.TRUE(正确答案) D.1.12E11 8.以下转义字符可以换行的是() [单选题] * A. \\ B.\b C.\https://mip.book118.com/html/2022/1108/8114043060005011.shtm