简述select语句的完整语法_简述SQL语言中SELECT语句的基本结构

匿名用户

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='杨全')

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值