Oracle_5ROWNUMCreateNewUser: Back up a table

Source: Internet
Author: User
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)
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.