Rownum is an ending field appended to each table by oracle. It records the row number of each row. One drawback of Oracle is that rownum can only be used with rsquo; lt; rsquo; or rsq.
Rownum is an ending field appended to each table by oracle. It records the row number of each row. One drawback of Oracle is that rownum can only be used with rsquo; lt; rsquo; or rsq.
Rownum is an ending field appended to each table by Oracle. It records the row number of each row. One drawback of Oracle is that rownum can only be used with '<' or '<=. If the value is greater than or equal to this value, other methods are available.
Top 5 with the highest salary
Select ename, sal
From (select ename, sal
From emp
Order by sal desc)
Where rownum <= 5;
Salary
Select ename, sal
From (select ename, sal, rownum r
From (select ename, sal
From emp
Order by sal desc)
)
Where r <= 10 and r> = 6;
Create New User
First backup ( Backup scott), enter the following command in the command line, and follow the prompts to operate
Exp
Then create a user Create user, switch to the administrator user under sqlplus, and enter
Create user USER_NAME (such as: lue) identified by password (lue) default tablespace users quota (quota) 10 M on users is to allocate 10 M space to users
The second step is to assign permissions to the new user. command:
Grant create session (LOGIN permission), creat table, create view to lue
Last import data Import the data, enter the following command in the command line, and follow the prompts;
Imp
An SQL interview question
There are 3 tables S, C, SC
S (sno, sname) stands for (student ID, name)
C (cno, cname, cteacher) representative (course number, course name, classroom)
SC (sno, cno, scgrade) representative (student ID, course number, score)
Problem:
1, Find out the names of all students who have not selected "liming ".
2, Lists the names and average scores of two or more failed students
3, Names of all students who have studied course 1 and course 2
Answer:
// Answer 1:
Select sname
From S join SC on (s. sno = SC. sno) join C (c. cno = SC. cno)
Where C. cteacher <> 'liming ';
// Answer 2:
Select sname
Where sno in (select sno, count (*)
From SC
Where scgrade <60
Group by sno
Having count (*)> 1 );
// Answer 3:
// Method 1:
Select sname
From S join (select sno
From SC
Where C. cno = 1 and C. cno = 2) t
On (S. sno = t. sno );
// Method 2:
Select sname
From S
Where sno in (select sno
From SC
Where cno = 1 and cno in (select distinct sno
From SC
Where cno = 2)
);