oracle basic operations and tips

- Fuzzy query
--1 address the query as "Shandong" student name, phone, address.
The SELECT studentName, Phone, address
from Student
the WHERE address like 'Shandong%';

. --2 query name contains "database" of information subject words
the SELECT *
from Subject
the WHERE SubjectName like '% database%';


. --3 Inquiries to "1387" at the beginning of the student information
the SELECT *
from Student
the WHERE Phone like '1387%';

. --4 query surnamed Jiang, the name of a single student information
the SELECT *
from Student
the WHERE studentName like 'Ginger _';

. --5 inquiry number 1004 school students to participate in courses numbered 1,2,3 test scores information
the SELECT *
from the Result
the WHERE studentno = 1004 and subjectno in (1,2,3);


--6. Queries date of birth between 1980-1-1 1989-12-31 student information to
the SELECT *
from Student
the WHERE borndate the BETWEEN to_date ( '1980-1-1', 'YYYY-MM-DD') and to_date ( '1989-12-31', 'YYYY- MM-DD');

- Packet Statistics:
--1 number of queries course each semester / year the number more than 50 hours.
The SELECT gradeid grades, count (*) Lessons
from Subject
the WHERE classhour> 50
Group by gradeid;


. --2 query the average age of each semester students
select gradeid year, avg (months_between (sysdate, borndate ) / 12) The average age
from Student
Group by gradeid;

 

. --3 number of students per semester in Beijing's inquiry
select gradeid grades, count (*) number
from Student
the WHERE address like 'Beijing%'
Group by gradeid;

- 4. Query students take the exam, the average student who has failed record, and in descending order according to the results
select studentno student number, avg (studentresult) grade point average
from the Result
Group by studentno
the HAVING AVG (studentresult)> = 60
the Order by 2 desc;


- 5. Discover the test date for the course March 22, 2010 of a passing average
select subjectno course number, avg (studentresult) Average points
from the Result
the WHERE examdate = to_date ( '2010-03-22', 'YYYY-MM -DD ') and studentresult> = 60
Group by subjectno;


. --6 query at least twice failing the exam the student number, the number of fail
select studentno student number, the number of count (studentno) failed
from the Result
the WHERE studentresult <60
Group by studentno
the HAVING count (studentno)> = 2;

 

Guess you like

Origin www.cnblogs.com/javahua/p/11563278.html