<< Chapter < Page Chapter >> Page >

SQL cũng có cho phép các so sánh<SOME,>= SOME,<= SOME, = SOME,<>SOME

  • ALL

"Tìm tất cả các tên của các chi nhánh có tài sản lớn hơn tài sản của bất kỳ chi nhánh nào đóng tại Brooklyn"

SELECT Branch_name

FROM Branch

WHERE Assets>ALL (SELECT Assets

FROM Branch

WHERE Branch_citty = 'Brooklyn')

SQL cũng cho phép các phép so sánh:<ALL,<= ALL,>ALL,>= ALL, = ALL,<>ALL.

"Tìm chi nhánh có số cân đối trung bình lớn nhất"

SQL không cho phép hợp thành các hàm tính gộp, như vậy MAX(AVG (...)) là không được phép. Do vậy, ta phải sử dụng câu vấn tin con như sau:

SELECT Branch_name

FROM Account

GROUP BY Branch_name

HAVING AVG (Balance)>= ALL (SELECT AVG (balance)

FROM Account

GROUP BY Branch_name)

Thử các quan hệ rỗng

"tìm tất cả các khách hàng có cả vay lẫn tài khoản ở ngân hàng"

SELECT Customer_name

FROM Borrower

WHERE EXISTS (SELECT *

FROM Depositor

WHERE Depositor.Customer_name = Borrower.Customer_name)

Cấu trúc EXISTS trả lại giá trị true nếu quan hệ kết quả của câu vấn tin con không rỗng. SQL cũng cho phép sử dụng cấu trúc NOT EXISTS để kiểm tra tính không rỗng của một quan hệ.

"Tìm tất cả các khách hàng có tài khoản tại mỗi chi nhánh đóng tại Brooklyn"

SELECT DISTINCT S.Customer_name

FROM Depositor AS S

WHERE NOT EXISTS( ( SELECT Branch_name

FROM Branch

WHERE Branch_city = 'Brooklyn')

EXCEPT

( SELECT R.branch_name

FROM Depositor AS T, Account AS R

WHERE T.Acoount_number = R.Account_number

AND S.Customer_name = T.Customer_name) )

Thử không có các bộ trùng

SQL đưa vào cấu trúc UNIQUE để kiểm tra việc có bộ trùng trong quan hệ kết quả của một câu vấn tin con.

"Tìm tất cả khách hàng chỉ có một tài khoản ở chi nhánh Perryridge"

SELECT T.Customer_name

FROM Depositor AS T

WHERE UNIQUE (SELECT R.Customer_name

FROM Account, Depositor AS R

WHERE T.Customer_name = R.Customer_name AND

R.Account_number = Account.Acount_number ANDAccount.Branch_name = 'Perryridge')

Ta có thể thử sự tồn tại của các bộ trùng trong một vấn tin con bằng cách sử dụng cấu trúc NOT UNIQUE

"Tìm tất cả các khách hàng có ít nhất hai tài khoản ở chi nhánh Perryridge"

SELECT DISTINCT T.Customer_name

FROM Account, Depositor AS T

WHERE NOT UNIQUE ( SELECT R.Customer_name

FROM Account, Depositor AS R

WHERE T.Customer_name=R.Customer_name

ANDR.Account_number = Account.Account_number

AND Account.Branch_name = 'Perryridge')

UNIQUE trả lại giá rị false khi và chỉ khi quan hệ có hai bộ trùng nhau. Nếu hai bộ t1, t2 có ít nhất một trường null, phép so sánh t1 = t2 cho kết quả false. Do vậy UNIQUE có thể trả về giá trị true trong khi quan hệ có nhiều bộ trùng nhau nhưng chứa trường giá trị null !

Quan hệ dẫn xuất

SQL92 cho phép một biểu thức vấn tin con được dùng trong mệnh đề FROM. Nếu biểu thức như vậy được sử dụng, quan hệ kết quả phải được cho một cái tên và các thuộc tính có thể được đặt tên lại (bằng mệnh đề AS)

Ví dụ câu vấn tin con:

(SELECT Branch_name, AVG(Balance)

FROM Account

GROUP BY Branch_name)

AS result (Branch_name, Avg_balace)

Sinh ra quan hệ gồm tên của tất cả các chi nhánh, và số cân đối trung bình tương ứng. Quan hệ này được đặt tên là result với hai thuộc tính Branch_name và Avg_balance.

Questions & Answers

if three forces F1.f2 .f3 act at a point on a Cartesian plane in the daigram .....so if the question says write down the x and y components ..... I really don't understand
Syamthanda Reply
hey , can you please explain oxidation reaction & redox ?
Boitumelo Reply
hey , can you please explain oxidation reaction and redox ?
Boitumelo
for grade 12 or grade 11?
Sibulele
the value of V1 and V2
Tumelo Reply
advantages of electrons in a circuit
Rethabile Reply
we're do you find electromagnetism past papers
Ntombifuthi
what a normal force
Tholulwazi Reply
it is the force or component of the force that the surface exert on an object incontact with it and which acts perpendicular to the surface
Sihle
what is physics?
Petrus Reply
what is the half reaction of Potassium and chlorine
Anna Reply
how to calculate coefficient of static friction
Lisa Reply
how to calculate static friction
Lisa
How to calculate a current
Tumelo
how to calculate the magnitude of horizontal component of the applied force
Mogano
How to calculate force
Monambi
a structure of a thermocouple used to measure inner temperature
Anna Reply
a fixed gas of a mass is held at standard pressure temperature of 15 degrees Celsius .Calculate the temperature of the gas in Celsius if the pressure is changed to 2×10 to the power 4
Amahle Reply
How is energy being used in bonding?
Raymond Reply
what is acceleration
Syamthanda Reply
a rate of change in velocity of an object whith respect to time
Khuthadzo
how can we find the moment of torque of a circular object
Kidist
Acceleration is a rate of change in velocity.
Justice
t =r×f
Khuthadzo
how to calculate tension by substitution
Precious Reply
hi
Shongi
hi
Leago
use fnet method. how many obects are being calculated ?
Khuthadzo
khuthadzo hii
Hulisani
how to calculate acceleration and tension force
Lungile Reply
you use Fnet equals ma , newtoms second law formula
Masego
please help me with vectors in two dimensions
Mulaudzi Reply
how to calculate normal force
Mulaudzi
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Hệ quản trị cơ sở dữ liệu. OpenStax CNX. Jul 31, 2009 Download for free at http://cnx.org/content/col10838/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Hệ quản trị cơ sở dữ liệu' conversation and receive update notifications?

Ask