-- 查询满足条件的元组: Select … From … where Select*from student where sdept <>'IS'; Select sno, sage from student where sname ='张立';
-- between and Selectdistinct sno from sc Wherenot grade between60and90; -- [in | not in] Select sno, grade from sc Where cno in ('001', '002', '003'); Select sno, grade from sc Where cno notin ('001', '002', '003'); -- Like / not like -- 百分号(%)与任意多个(含零个)任意字符匹配;下划线(_)与一个任意字符匹配,换码字符'\'使后面的通配符失效,变成普通字符 Select*from student where sname like'刘军%'; Select*from student where sname like'刘_军'; Select*from student where sname like'刘军'; Select*from student where sname = '刘军%';
-- 空值匹配 null Select*from student Where sdept isnull; Select*from student Where sdept =null; -- 不报错,但无结果
查询结果排序
1 2 3 4 5
-- 结果排序 Select sno, sname from student Where sdept ='IS'Orderby sage asc; Select sno, grade from sc Where cno ='A'Orderby grade desc; -- top N Select top 10 sno, grade from sc Where cno='c1'Orderby grade desc;
集函数
1 2 3 4 5
-- 集函数(除count外,集函数只处理非空值,这对求平均值有重要意义) Selectcount(*) from student where sdept='IS'; Selectcount(sno) , count(distinct sno) from sc; Selectcount(*) 数, sum(grade) 和, avg(grade) 均, max(grade) 大, min(grade) 小 from sc where sno='001';