any(some)、all 谓词的 SQL 写法,其实你用得多了就发现——嗯,它们看着挺“高端”,但多时候都能被别的写法轻松替代。比如查询比 CS 系某学生年纪小的其他系同学,用ANY或者ALL都行,其实一句MAX也能搞定。实战里,选你看着最顺手的写就好,别死磕语法。

比方说下面这句:

select sname, sage from student 
where sage < any sdept = 'CS'>

是不是有点绕?你用MAX其实更清爽:

select sname, sage from student 
where sage < (select max(sage) from student where sdept = 'CS') 
and sdept != 'CS'

意思一样,写法更利落。

如果你想深入挖掘这些 SQL 谓词的玩法,可以看看下面这几个资料,还挺系统的: