Select 查询语句
语法:SELECT [ALL|DISTINCT] <目标列表达式> [AS 列名]
[,<目标列表达式> [AS 列名] ...] FROM <表名> [,<表名>…]
[WHERE <条件表达式> [AND|OR <条件表达式>...]
[GROUP BY 列名[HA VING <条件表达式>>
[ORDER BY 列名[ASC | DESC>
解释:[ALL|DISTINCT] ALL:全部;DISTINCT:不包括重复行
<目标列表达式> 对字段可使用A VG、COUNT、SUM、MIN、MAX、运算符等
<条件表达式>
查询条件谓词
比较=、>,<,>=,<=,!=,<>,
确定范围BETWEEN AND、NOT BETWEEN AND
确定集合IN、NOT IN
字符匹配LIKE(“%”匹配任何长度,“_”匹配一个字符)、NOT LIKE
空值IS NULL、IS NOT NULL
子查询ANY、ALL、EXISTS
集合查询UNION(并)、INTERSECT(交)、MINUS(差)
多重条件AND、OR、NOT
<GROUP BY 列名> 对查询结果分组
[HA VING <条件表达式>] 分组筛选条件
[ORDER BY 列名[ASC | DESC> 对查询结果排序;ASC:升序DESC:降序
例1:select student.sno as 学号, as 姓名, course as 课程名, score as 成绩from score,student where student.sid=score.sid and score.sid=:sid
例2:select student.sno as 学号, as 姓名,A VG(score) as 平均分from score,student where student.sid=score.sid and student.class=:class and (term=5 or term=6) group by student.sno, having count(*)>0 order by 平均分DESC
例3:select * from score where sid like '9634'
例4:select * from student where class in (select class from student where name='陈小小')。