Mysql database basic statement training questions detailed code
mysql database basic statement training question detailed code
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for course -- ---------------------------- DROP TABLE IF EXISTS `course`; CREATE TABLE `course` ( `cno` varchar(10) DEFAULT NULL, `Cname` varchar(255) DEFAULT NULL, `tno` varchar(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of course -- ---------------------------- INSERT INTO `course` VALUES ('01', '语文', '02'); INSERT INTO `course` VALUES ('02', '数学', '01'); INSERT INTO `course` VALUES ('03', '英语', '03'); -- ---------------------------- -- Table structure for sc -- ---------------------------- DROP TABLE IF EXISTS `sc`; CREATE TABLE `sc` ( `sno` varchar(10) DEFAULT NULL, `cno` varchar(10) DEFAULT NULL, `score` decimal(18,1) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of sc -- ---------------------------- INSERT INTO `sc` VALUES ('01', '01', '80.0'); INSERT INTO `sc` VALUES ('01', '02', '90.0'); INSERT INTO `sc` VALUES ('01', '03', '99.0'); INSERT INTO `sc` VALUES ('02', '02', '60.0'); INSERT INTO `sc` VALUES ('02', '03', '80.0'); INSERT INTO `sc` VALUES ('03', '01', '80.0'); INSERT INTO `sc` VALUES ('03', '02', '80.0'); INSERT INTO `sc` VALUES ('03', '03', '80.0'); INSERT INTO `sc` VALUES ('04', '01', '50.0'); INSERT INTO `sc` VALUES ('04', '02', '30.0'); INSERT INTO `sc` VALUES ('04', '03', '20.0'); INSERT INTO `sc` VALUES ('05', '01', '76.0'); INSERT INTO `sc` VALUES ('05', '02', '87.0'); INSERT INTO `sc` VALUES ('06', '01', '31.0'); INSERT INTO `sc` VALUES ('06', '03', '34.0'); INSERT INTO `sc` VALUES ('07', '02', '89.0'); INSERT INTO `sc` VALUES ('07', '03', '98.0'); -- ---------------------------- -- Table structure for student -- ---------------------------- DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `sno` varchar(10) DEFAULT NULL, `Sname` varchar(255) DEFAULT NULL, `Sage` datetime DEFAULT NULL, `Ssex` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of student -- ---------------------------- INSERT INTO `student` VALUES ('01', '赵雷', '1990-01-01 00:00:00', '男'); INSERT INTO `student` VALUES ('02', '钱电', '1990-12-21 00:00:00', '男'); INSERT INTO `student` VALUES ('03', '孙风', '1990-05-20 00:00:00', '男'); INSERT INTO `student` VALUES ('04', '李云', '1990-08-06 00:00:00', '男'); INSERT INTO `student` VALUES ('05', '周梅', '1991-12-01 00:00:00', '女'); INSERT INTO `student` VALUES ('06', '吴兰', '1992-03-01 00:00:00', '女'); INSERT INTO `student` VALUES ('07', '郑竹', '1989-07-01 00:00:00', '女'); INSERT INTO `student` VALUES ('08', '王菊', '1990-01-20 00:00:00', '女'); -- ---------------------------- -- Table structure for teacher -- ---------------------------- DROP TABLE IF EXISTS `teacher`; CREATE TABLE `teacher` ( `tno` varchar(10) DEFAULT NULL, `Tname` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of teacher -- ---------------------------- INSERT INTO `teacher` VALUES ('01', '张三'); INSERT INTO `teacher` VALUES ('02', '李四'); INSERT INTO `teacher` VALUES ('03', '王五'); -- ---------------------------- -- Table structure for users -- ---------------------------- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `id` int(10) NOT NULL AUTO_INCREMENT, `username` varchar(20) DEFAULT NULL, `password` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of users -- ---------------------------- INSERT INTO `users` VALUES ('1', 'aaa', 'ab\'c');
Student(Sno,Sname,Sage,Ssex) 学生表 Course(Cno,Cname,Tno) 课程表 SC(Sno,Cno,score) 成绩表 Teacher(Tno,Tname) 教师表 问题: 1、查询“001”课程比“002”课程成绩高的所有学生的学号; 2、查询平均成绩大于60分的同学的学号和平均成绩; 3、查询所有同学的学号、姓名、选课数、总成绩; 4、查询姓“李”的老师的个数; 5、查询没学过“叶平”老师课的同学的学号、姓名; 6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名; 7、查询学过“叶平”老师所教的所有课的同学的学号、姓名; 8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名; 9、查询所有课程成绩小于60分的同学的学号、姓名; 10、查询没有学全所有课的同学的学号、姓名; 11、查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名; 12、查询至少学过学号为“001”同学所有一门课的其他同学学号和姓名; 13、把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩; 14、查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名; 15、删除学习“叶平”老师课的SC表记录; 16、向SC表中插入一些记录,这些记录要求符合以下条件:没有上过编号“003”课程的同学学号、2、 号课的平均成绩; 17、按平均成绩从高到低显示所有学生的“数据库”、“企业管理”、“英语”三门的课程成绩,按如下形式显示: 学生ID,,数据库,企业管理,英语,有效课程数,有效平均分 18、查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分 19、按各科平均成绩从低到高和及格率的百分数从高到低顺序 20、查询如下课程平均成绩和及格率的百分数(用"1行"显示): 企业管理(001),马克思(002),OO&UML (003),数据库(004) 21、查询不同老师所教不同课程平均分从高到低显示 22、查询如下课程成绩第 3 名到第 6 名的学生成绩单:企业管理(001),马克思(002),UML (003),数据库(004) 23、统计列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[ <60] 24、查询学生平均成绩及其名次 25、查询各科成绩前三名的记录:(不考虑成绩并列情况) 26、查询每门课程被选修的学生数 28、查询男生、女生人数 29、查询姓“张”的学生名单 30、查询同名同性学生名单,并统计同名人数 31、1981年出生的学生名单(注:Student表中Sage列的类型是datetime) 32、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列 33、查询平均成绩大于85的所有学生的学号、姓名和平均成绩 34、查询课程名称为“数据库”,且分数低于60的学生姓名和分数 35、查询所有学生的选课情况; 36、查询任何一门课程成绩在70分以上的姓名、课程名称和分数; 37、查询不及格的课程,并按课程号从大到小排列 38、查询课程编号为003且课程成绩在80分以上的学生的学号和姓名; 39、求选了课程的学生人数 40、查询选修“叶平”老师所授课程的学生中,成绩最高的学生姓名及其成绩 41、查询各个课程及相应的选修人数 42、查询不同课程成绩相同的学生的学号、课程号、学生成绩 43、查询每门功成绩最好的前两名 44、统计每门课程的学生选修人数(超过10人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,查询结果按人数降序排列,若人数相同,按课程号升序排列 45、检索至少选修两门课程的学生学号 46、查询全部学生都选修的课程的课程号和课程名 47、查询没学过“叶平”老师讲授的任一门课程的学生姓名 48、查询两门以上不及格课程的同学的学号及其平均成绩 49、检索“004”课程分数小于60,按分数降序排列的同学学号 50、删除“002”同学的“001”课程的成绩
The above is the content of the mysql database basic statement training question detailed code. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
