匿名用户
1级
2012-02-28 回答
Select 查询语句
语法:SELECT [ALL|DISTINCT] [AS 列名]
[, [AS 列名] ...] FROM [,…]
[WHERE [AND|OR ...]
[GROUP BY 列名 [HAVING >
[ORDER BY 列名 [ASC | DESC>
解释:[ALL|DISTINCT] ALL:全部; DISTINCT:不包括重复行
对字段可使用AVG、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
对查询结果分组
[HAVING ] 分组筛选条件
[ORDER BY 列名 [ASC | DESC> 对查询结果排序;ASC:升序 DESC:降序
例1: select student.sno as 学号, student.name as 姓名, course as 课程名, score as 成绩 from score,student where student.sid=score.sid and score.sid=:sid
例2:select student.sno as 学号, student.name as 姓名,AVG(score) as 平均分 from score,student where student.sid=score.sid and student.class=:class and (term=5 or term=6) group by student.sno, student.name 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='杨全')