Database - Select

2010-03-09 6:39 am
試解釋點解以下 Syntax 正確 ?

WHERE OverduePay>=ALL (SELECT OverduePay FROM Student)


圖片參考:http://imgcld.yimg.com/8/n/HA01048025/o/701003080166313873424520.jpg

回答 (2)

2010-03-10 2:02 pm
✔ 最佳答案
Let me illustrate with an example.

Name OverduePay
Student1 10
Student2 20
Student3 30

The subquery (Select OverduePay From Student) returns 10, 20 and 30.

SELECT Name, OverduePay FROM Student WHERE OverduePay >= ALL (SELECT OverduePay FROM Student)

is identical to

SELECT Name, OverduePay FROM Student WHERE OverduePay >= 10 AND OverduePay>= 20 AND OverduePay>= 30

Using ALL is to compare the expression with ALL the values returned by the subquery and the result is True when all values meet the condition; otherwise the result is False.

In this example, only Student3 is true.

There is also SOME | ANY, which is equivalent to using OR in the WHERE clause of the sql statement.

Ref:
http://msdn.microsoft.com/en-us/library/ms178543.aspx
http://msdn.microsoft.com/en-us/library/ms175064.aspx
2010-03-09 9:42 am
>=ALL (SELECT OverduePay FROM Student)

means the left selection must be greater than or equal to ALL the values selected inside the right bracket. In this case, it is equivalent to greater than or equal to the maximum value of OverduePay of the Student table.


For the whole SQL statement, it is to select the rows that have maximum OverduePay value.


收錄日期: 2021-04-25 20:34:28
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100308000051KK01663

檢視 Wayback Machine 備份