<< Chapter < Page Chapter >> Page >

Mệnh đề select

Ta tìm hiểu mệnh đề SELECT bằng cách xét một vài ví dụ:

"Tìm kiếm tất cả các tên các chi nhánh trong quan hệ cho vay (loan)":

SELECT Branch_name

FROM Loan;

Kết quả là một quan hệ gồm một thuộc tính Tên chi nhánh (Branch_name)

Nếu muốn quan hệ kết quả không chứa các tên chi nhánh trùng nhau:

SELECT DISTINCT Branch_name

FROME Loan;

Từ khoá ALL được sử dụng để xác định tường minh rằng các giá trị trùng không bị xoá và nó là mặc nhiên của mệnh đề SELECT.

Ký tự * được dùng để chỉ tất cả các thuộc tính:

SELECT *

FROM Loan;

Sau mệnh đề SELECT cho phép các biểu thức số học gồm các phép toán +, -, *, / trên các hằng hoặc các thuộc tính:

SELECT Branch_name, Loan_number, amount * 100

FROM Loan;

Mệnh đề where

“Tìm tất cả các số cho vay ở chi nhánh tên Perryridge với số lượng vay lớn hơn1200$"

SELECT Loan_number

FROM Loan

WHERE Branch_name = ‘Perryridge’ AND Amount>1200;

SQL sử dụng các phép nối logic: NOT, AND, OR. Các toán hạng của các phép nối logic có thể là các biểu thức chứa các toán tử so sánh =,>=,<>,<,<=.

Toán tử so sánh BETWEEN được dùng để chỉ các giá trị nằm trong một khoảng:

SELECT Loan_number

FROM Loan

WHERE Amount BETWEEN 50000 AND 100000;

SELECT Loan_number

FROM Loan

WHERE Amount>= 50000 AND Amount<= 100000;

Ta cũng có thể sử dụng toán tử NOT BETWEEN.

Mệnh đề from

"Trong tất cả các khách hàng có vay ngân hàng tìm tên và số cho vay của họ"

SELECT DISTINCT Customer_name, Borrower.Loan_number

FROM Borrower, Loan

WHERE Borrower.Loan_number = Loan.Loan_number;

SQL sử dụng cách viết<tên quan hệ>.<tên thuộc tính>để che dấu tính lập lờ trong trường hợp tên thuộc tính trong các sơ đồ quan hệ trùng nhau.

"Tìm các tên và số cho vay của tất cả các khách hàng có vay ở chi nhánh Perryridge"

SELECT Customer_name, Borrower.Loan_number

FROM Borrower, Loan

WHERE Borrower.Loan_number = Loan.Loan_number AND

Branch_name =’Perryridge’;

Các phép đổi tên

SQL cung cấp một cơ chế đổi tên cả tên quan hệ lẫn tên thuộc tính bằng mệnh đề dạng:

<tên cũ>AS<tên mới>

mà nó có thể xuất hiện trong cả mệnh đề SELECT lẫn FROM

SELECT DISTINCT Customer_name, Borrower.Loan_number

FROM Borrower, Loan

WHERE Borrower.Loan_number = Loan.Loan_number AND

Branch_name =’Perryridge’;

Kết quả của câu vấn tin này là một quan hệ hai thuộc tính: Customer_name, Loan_number

Đổi tên thuộc tính của quan hệ kết quả:

SELECT Customer_name, Borrower.Loan_number AS Loan_Id

FROM Borrower, Loan

WHERE Borrower.Loan_number = Loan.Loan_number AND

Branch_name =’Perryridge’;

Các biến bộ (tuple variables)

Các biến bộ được định nghĩa trong mệnh đề FROM thông qua sử dụng mệnh đề AS:

SELECT DISTINCT Customer_name, T.Loan_number

FROM Borrower AS T, Loan AS S

WHERE T.Loan_number = S.Loan_number AND

Branch_name =’Perryridge’;

“Tìm các tên của tất cả các chi nhánh có tài sản lớn hơn ít nhất một chi nhánh ở Brooklyn“

SELECT DISTINCT T.branch_name

FROM Branch AS T, Banch AS S

WHERE T.assets>S.assets AND S.Branch_City = ‘Brooklyn’

SQL92 cho phép sử dụng các viết (v1, v2, ..., vn) để ký hiệu một n-bộ với các giá trị v1, v2, ..., vn. Các toán tử so sánh có thể được sử dụng trên các n-bộ và theo thứ tự tự điển. Ví dụ (a1, b1)<= (a2, b2) là đúng nếu (a1<b1) OR ((a1 = b1) AND (a2<b2)).

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
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