Home Database Mysql Tutorial 数据库面试题目总结

数据库面试题目总结

Jun 07, 2016 pm 03:36 PM
business information training post Establish Summarize database manage interview

为管理岗位业务培训信息,建立3个表: S (S#,SN,SD,SA) S#,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄 C (C#,CN ) C#,CN 分别代表课程编号、课程名称 SC ( S#,C#,G ) S#,C#,G 分别代表学号、所选修的课程编号、学习成绩 1. 使用标准SQL嵌套语句查

 

   为管理岗位业务培训信息,建立3个表:
  S (S#,SN,SD,SA) S#,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄
  C (C#,CN ) C#,CN 分别代表课程编号、课程名称
  SC ( S#,C#,G ) S#,C#,G 分别代表学号、所选修的课程编号、学习成绩
  1. 使用标准SQL嵌套语句查询选修课程名称为’税收基础’的学员学号和姓名
  2. 使用标准SQL嵌套语句查询选修课程编号为’C2’的学员姓名和所属单位
  3. 使用标准SQL嵌套语句查询不选修课程编号为’C5’的学员姓名和所属单位
  4. 使用标准SQL嵌套语句查询选修全部课程的学员姓名和所属单位
  5. 查询选修了课程的学员人数
  5. 查询选修了课程的学员人数
  
     题目2

  问题描述:

  已知关系模式:

  S (SNO,SNAME) 学生关系。SNO 为学号,SNAME 为姓名

  C (CNO,CNAME,CTEACHER) 课程关系。CNO 为课程号,CNAME 为课程名,CTEACHER 为任课教师

  SC(SNO,CNO,SCGRADE) 选课关系。SCGRADE 为成绩

  1. 找出没有选修过“李明”老师讲授课程的所有学生姓名
  2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩
  3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名
  4. 列出“1”号课成绩比“2”号同学该门课成绩高的所有学生的学号
  5. 列出“1”号课成绩比“2”号课成绩高的所有学生的学号及其“1”号课和“2”号课的成绩

  


为管理岗位业务培训信息,建立3个表:
  S (S#,SN,SD,SA) S#,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄
  C (C#,CN ) C#,CN 分别代表课程编号、课程名称
  SC ( S#,C#,G ) S#,C#,G 分别代表学号、所选修的课程编号、学习成绩
  1. 使用标准SQL嵌套语句查询选修课程名称为’税收基础’的学员学号和姓名

  --实现代码:

  Select SN,SD FROM S
  Where [S#] IN(
  Select [S#] FROM C,SC
  Where C.[C#]=SC.[C#]
  AND CN=N'税收基础') 

  2. 使用标准SQL嵌套语句查询选修课程编号为’C2’的学员姓名和所属单位

  --实现代码:

  Select S.SN,S.SD FROM S,SC

  Where S.[S#]=SC.[S#]

  AND SC.[C#]='C2'

  3. 使用标准SQL嵌套语句查询不选修课程编号为’C5’的学员姓名和所属单位

  --实现代码:

  Select SN,SD FROM S

  Where [S#] NOT IN(

  Select [S#] FROM SC

  Where [C#]='C5')

  4. 使用标准SQL嵌套语句查询选修全部课程的学员姓名和所属单位
  --实现代码:

  Select SN,SD FROM S

  Where [S#] IN(

  Select [S#] FROM SC

  RIGHT JOIN

  C ON SC.[C#]=C.[C#] GROUP BY [S#]

  HAVING COUNT(*)=COUNT([S#]))

  5. 查询选修了课程的学员人数

  --实现代码:

  Select 学员人数=COUNT(DISTINCT [S#]) FROM SC

  6. 查询选修课程超过5门的学员学号和所属单位

  --实现代码:

  Select SN,SD FROM S

  Where [S#] IN(

  Select [S#] FROM SC

  GROUP BY [S#]

  HAVING COUNT(DISTINCT [C#])>5)

      题目2

  问题描述:

  已知关系模式:

  S (SNO,SNAME) 学生关系。SNO 为学号,SNAME 为姓名

  C (CNO,CNAME,CTEACHER) 课程关系。CNO 为课程号,CNAME 为课程名,CTEACHER 为任课教师

  SC(SNO,CNO,SCGRADE) 选课关系。SCGRADE 为成绩

  1. 找出没有选修过“李明”老师讲授课程的所有学生姓名

  --实现代码:
   select sname from s where sno in
   (select sno from sc,c where sc.cno=c.cno and c.cteachere="李明")
  
  Select SNAME FROM S

  Where NOT EXISTS(

  Select * FROM SC,C

  Where SC.CNO=C.CNO

  AND CNAME='李明'

  AND SC.SNO=S.SNO)

  2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩

  --实现代码:

   Select S.SNO,S.SNAME,AVG_SCGRADE=AVG(SC.SCGRADE)

  FROM S,SC,(

  Select SNO

  FROM SC

  Where SCGRADE

  GROUP BY SNO

  HAVING COUNT(DISTINCT CNO)>=2

  )A Where S.SNO=A.SNO AND SC.SNO=A.SNO

  GROUP BY S.SNO,S.SNAME

  3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名

  --实现代码:

  Select S.SNO,S.SNAME

  FROM S,(

  Select SC.SNO

  FROM SC,C

  Where SC.CNO=C.CNO

  AND C.CNAME IN('1','2')

  GROUP BY SNO

  HAVING COUNT(DISTINCT CNO)>=2

  )SC Where S.SNO=SC.SNO

  4. 列出“1”号课成绩比“2”号同学该门课成绩高的所有学生的学号

  --实现代码:
    select sc.sno from sc,
    (select sc1.sno from
     (select sc.sno,sc.scgrade from sc,c where sc.cno=c.cno and c.cname='1')sc1,
     (select sc.sno,sc.scgrade from sc,c where sc.cno=c.cno and c.cname='1')sc2,
    where sc1.sno=sc2.sno and sc1.sgrade>sc2.scgrade
    )scc
    where sc.sno=scc.sno

  Select S.SNO,S.SNAME

  FROM S,(

  Select SC1.SNO

  FROM SC SC1,C C1,SC SC2,C C2

  Where SC1.CNO=C1.CNO AND C1.NAME='1'

  AND SC2.CNO=C2.CNO AND C2.NAME='2'

  AND SC1.SCGRADE>SC2.SCGRADE

  )SC Where S.SNO=SC.SNO

  5. 列出“1”号课成绩比“2”号课成绩高的所有学生的学号及其“1”号课和“2”号课的成绩

  --实现代码:

  Select S.SNO,S.SNAME,SC.[1号课成绩],SC.[2号课成绩]

  FROM S,(

  Select SC1.SNO,[1号课成绩]=SC1.SCGRADE,[2号课成绩]=SC2.SCGRADE

  FROM SC SC1,C C1,SC SC2,C C2

  Where SC1.CNO=C1.CNO AND C1.NAME='1'

  AND SC2.CNO=C2.CNO AND C2.NAME='2'

  AND SC1.SCGRADE>SC2.SCGRADE

  )SC Where S.SNO=SC.SNO

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Golang framework interview questions collection Golang framework interview questions collection Jun 02, 2024 pm 09:37 PM

The Go framework is a set of components that extend Go's built-in libraries, providing pre-built functionality (such as web development and database operations). Popular Go frameworks include Gin (web development), GORM (database operations), and RESTful (API management). Middleware is an interceptor pattern in the HTTP request processing chain and is used to add functionality such as authentication or request logging without modifying the handler. Session management maintains session status by storing user data. You can use gorilla/sessions to manage sessions.

Lynk & Co Z10 sales start at 189,800 yuan, 800V version is priced at 229,800 yuan, pointing directly at Xiaomi SU7 Lynk & Co Z10 sales start at 189,800 yuan, 800V version is priced at 229,800 yuan, pointing directly at Xiaomi SU7 Jul 16, 2024 am 03:05 AM

Recently, a car blogger released the price of the Lynk & Co Z10, which is suspected to be exposed for sale. According to this employee from a Lynk & Co center in Nanning, Guangxi, the starting price of the Lynk & Co Z10 400V version is 189,800 yuan, while the starting price of the 800V version is 229,800 yuan. The employee also said that "starting at 180,000 yuan, Zhenxiang warning", which seems to imply that there may be more rights and interests during the first sale. Fenye Lynk & Co Z10 According to indirect reports from car bloggers, Lynk & Co Z10 is expected to be: Pre-sale time: July Official delivery: August Price: Starting price: 182,800 yuan Mid-range model: 192,800 yuan High-end version: 207,800 Yuan first launch discount: fenye Lynk & Co Z10 price around 8,000 yuan revealed

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

See all articles