Home Java JavaInterview questions Java high-frequency basic interview questions——(9)

Java high-frequency basic interview questions——(9)

Sep 14, 2020 am 11:21 AM
java Interview questions

Java high-frequency basic interview questions——(9)

If you want to become a qualified Java back-end developer, database knowledge is essential. The examination of familiarity with the database is also an examination of whether the person has solid basic skills.

(Recommendations for more related interview questions: java interview questions and answers)

Especially for junior developers, the interview may not ask about framework-related knowledge, but it will definitely There is no way to fail to examine database knowledge. Here we collect some common types of SQL statements, which will be helpful whether for daily development or preparing for interviews.

Basic table structure:

1

2

3

4

student(sno,sname,sage,ssex)学生表       

course(cno,cname,tno) 课程表       

sc(sno,cno,score) 成绩表

teacher(tno,tname) 教师表

Copy after login

101, query the student numbers of all students whose grades in course 1 are higher than those in course 2

1

2

3

4

select a.sno from

(select sno,score from sc where cno=1) a,

(select sno,score from sc where cno=2) b

where a.score>b.score and a.sno=b.sno

Copy after login

102, query the average grade greater than 60 The student number and average grade of the students who scored

1

2

3

4

select a.sno as "学号", avg(a.score) as "平均成绩"

from

(select sno,score from sc) a

group by sno having avg(a.score)>60

Copy after login

103, query the student number, name, number of courses taken, and total grade of all students

1

2

3

4

5

select a.sno as 学号, b.sname as 姓名,

count(a.cno) as 选课数, sum(a.score) as 总成绩

from sc a, student b

where a.sno = b.sno

group by a.sno, b.sname

Copy after login

or:

1

2

3

4

selectstudent.sno as 学号, student.sname as 姓名,

 count(sc.cno) as 选课数, sum(score) as 总成绩

from student left Outer join sc on student.sno = sc.sno

group by student.sno, sname

Copy after login

104, query the number of teachers with the surname "Zhang"

1

selectcount(distinct(tname)) from teacher where tname like '张%‘

Copy after login

or:

1

2

3

4

select tname as "姓名", count(distinct(tname)) as "人数"

from teacher

where tname like'张%'

group by tname

Copy after login

105, query the number of teachers who have not studied with "Zhang San" The student number and name of the student

1

2

3

select student.sno,student.sname from student

where sno not in (select distinct(sc.sno) from sc,course,teacher

where sc.cno=course.cno and teacher.tno=course.tno and teacher.tname='张三')

Copy after login

(recommended study: java course)

106, query the students who have studied both course 1 and course 2 Student number, name

1

2

3

select sno, sname from student

where sno in (select sno from sc where sc.cno = 1)

and sno in (select sno from sc where sc.cno = 2)

Copy after login

or:

1

2

3

4

5

selectc.sno, c.sname from

(select sno from sc where sc.cno = 1) a,

(select sno from sc where sc.cno = 2) b,

student c

where a.sno = b.sno and a.sno = c.sno

Copy after login

or:

1

2

select student.sno,student.sname from student,sc where student.sno=sc.sno and sc.cno=1

and exists( select * from sc as sc_2 where sc_2.sno=sc.sno and sc_2.cno=2)

Copy after login

107, check the teacher who has studied "Li Si" The student numbers and names of all students in all courses are

1

2

3

select a.sno, a.sname from student a, sc b

where a.sno = b.sno and b.cno in

(select c.cno from course c, teacher d where c.tno = d.tno and d.tname = '李四')

Copy after login

or:

1

2

3

select a.sno, a.sname from student a, sc b,

(select c.cno from course c, teacher d where c.tno = d.tno and d.tname = '李四') e

where a.sno = b.sno and b.cno = e.cno

Copy after login

108. Query the student numbers of all students whose scores in course number 1 are higher than those in course number 2. , Name

1

2

3

4

select a.sno, a.sname from student a,

(select sno, score from sc where cno = 1) b,

(select sno, score from sc where cno = 2) c

where b.score > c.score and b.sno = c.sno and a.sno = b.sno

Copy after login

109, query the student ID of all students whose scores are less than 60 points, name

1

2

select sno,sname from student

where sno not in (select distinct sno from sc where score > 60)

Copy after login

110, query at least one course with a student ID of 1 The student number and name of the classmates who are studying the same course

1

2

3

4

select distinct a.sno, a.sname

from student a, sc b

where a.sno <> 1 and a.sno=b.sno and

b.cno in (select cno from sc where sno = 1)

Copy after login

or:

1

2

3

4

5

6

7

select s.sno,s.sname

from student s,

(select sc.sno

from sc

where sc.cno in (select sc1.cno from sc sc1 where sc1.sno=1)and sc.sno<>1

group by sc.sno)r1

where r1.sno=s.sno

Copy after login

Related recommendations: java introductory tutorial

The above is the detailed content of Java high-frequency basic interview questions——(9). For more information, please follow other related articles on the PHP Chinese website!

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)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

See all articles