Oracle database administrator classic test questions [Oracle basic knowledge test]


提示:以下是本篇文章正文内容,下面案例可供参考

Database Fundamentals Test

Question 1: Table name: Score1, the specific records are as follows:

PERSON OUT
A win
A win
A burden
A burden
B win
B burden
B burden

(1) Please use SQL statements to count the number of wins and losses of A and B
第1种方法

select PERSON,
count(case OUT
when '胜' then
1
end) as 胜的次数,
count(case OUT
when '负' then
1
     end) as 负的次数
from Score1
group by PERSON;

第2种方法

select PERSON,
       count(case OUT
               when '胜' then
                1
             end) as 胜的次数,
       count(case OUT
               when '负' then
                1
             end) as 负的次数
  from Score1
 group by PERSON;

(2) Please use the SQL statement to find out the records where A and B win and lose times greater than 1

select PERSON,OUT from Score1 group by PERSON,OUT having count(*)>1;

Question 2: Table name: Team, which stores four teams, namely a, b, c, d. Now the four teams are competing, and a SQL statement is used to display all possible game combinations

NAME
a
b
c
d
select a.Name    
       , b.Name  
  from Team a, Team b
 where a.Name < b.Name;

Question 3: In order to enrich the lives of employees, the company offers art classes and fitness classes every week. The following are the courses offered by the two classes and the class attendance of employees last week:

Art class: table name: tablename_RX

time Courses Class employee (Empno)
Monday A 001
Tuesday B 002
Wednesday C 003
Thursday D 004

Fitness class: table name: tablename_HX

time Courses Class employee (Empno)
Monday E 002
Tuesday F 005
Wednesday G 001
Thursday H 003

(1) Use SQL statements to count the employees who participated in two shifts last week
第1种方法

select rx.Empno
  from tablename_RX rx, tablename_HX hx
 where rx.Empno = hx.Empno;

第2种方法

select rx.Empno 
from tablename_RX rx inner join tablename_HX hx
 on rx.Empno = hx.Empno;

第3种方法

select rx.Empno
from tablename_Rx rx
where Exists
(select * from tablename_HX hx
 where rx.Empno = hx.Empno)

(2) Use SQL statements to count employees who only participated in one class last week
第1种方法

(select Empno from tablename_RX
union
select Empno from tablename_HX)
minus
(select tablename_RX.Empno
  from tablename_RX, tablename_HX
 where tablename_RX.Empno = tablename_HX.Empno);

第2种方法

select rx.Empno
from tablename_Rx rx
where not Exists
(select * from tablename_HX hx
 where rx.Empno = hx.Empno)
 union
  select hx.Empno
from tablename_HX hx
where not Exists
(select * from tablename_Rx rx
 where rx.Empno = hx.Empno)

(3) Count the number of classes attended by employees last week
第1种方法

select EMPNO, count(*)
  from (select EMPNO, count(*)
          from tablename_Rx
         group by EMPNO
        union all
        select EMPNO, count(*) from tablename_HX group by EMPNO)
 group by EMPNO order by EMPNO;

第2种方法

 select a.empno, count(a.empno)
   from (select *
           from tablename_RX
         union
         select * from tablename_HX) a
  group by EMPNO
  order by EMPNO;

Question 4: Table name: Score, recorded as follows:

ST_NO Chinese Math English
001 70 80 58

(1) Use the SQL statement to output the following results (greater than or equal to 80 means excellent, greater than or equal to 60 means pass, less than 60 means fail):

ST_NO Chinese Math English
001 pass excellent failed
select ST_NO,(case
when Chinese >= 80 then
'优秀'
when Chinese >= 60 then
'及格'
     else
'不及格'
end) as Chinese,
(case
when Math >= 80 then
'优秀'
when Math >= 60 then
'及格'
else
'不及格'
end) as Math,
(case
when English >= 80 then
    '优秀'
when English >= 60 then
'及格'
else
'不及格'
end) as English
from tablename_Score;

(2) Output the name and score of the course with the highest score in Chinese, Math, and English for 001 students

select 课程, 成绩
from (select ST_NO, 'Chinese' 课程, Chinese 成绩
     from tablename_Score
union all
select ST_NO, 'Math', Math 成绩
from tablename_Score
union all
select ST_NO, 'English' 课程, English 成绩
from tablename_Score)
where 成绩=
(select max(成绩)from (
select ST_NO, 'Chinese' 课程, Chinese 成绩
from tablename_Score
union all
select ST_NO, 'Math', Math 成绩
         from tablename_Score
union all
select ST_NO, 'English' 课程, English 成绩
from tablename_Score
 ));

Question 5: Use SQL statements to query the date of the last day of a certain month in a certain year

//select last_day(to_date('202207','yyyymm' ))from dual;
select last_day(to_date(sysdate))from dual;

Guess you like

Origin blog.csdn.net/qq_40670171/article/details/130376090