/********
SQL单表查询条件汇总
/
1,
where grade>=60;
2,where sage between 20 and 22;
3,where sage not between 20 and 22;
4,where sdept in(‘计算机学院’,‘交通学院’,‘机械学院’);/// 谓词in 后可以跟多个值。
5,where sdept not in(‘计算机学院’,‘交通学院’,‘机械学院’);
///使用谓词Like进行字符串匹配查找
6,where sno like ‘17110203043’===where son=‘1710203043’;
///在Like中涉及两个通配符%和_
///a%b表示以a开头以b结尾的字符串,a%表示以a开头的字符串…
///下划线_表示任意"一个"字符。for example:a_表示以a开头的且长度为2的字符串。
7,where sname not like ‘董%’;
8,where grade is null;///查询选课但成绩为空的学生。
9,where sdept='计算机学院’and sage>20;
10,order by grade desc;
11,group by son having count()>6;
/*****
SQL连接查询
内连接:等值连接,自然连接
外连接:左外连接,右外连接,全连接
自身链接
/
1,where student.sno=sc.son and sc.sno=2 and sc.grade>95;///等值连接,将Student与sc 中同一学生的元组连接起来
2,select from student natural join sc ;///自然连接不许指定具体列,默认。
3,select from student left outer join sc using (sno);///左外连接,使用using 可以去除重复组。
4,select lfrom course s1,course s2 where s1.cno=s2.spno;///自身连接,使用别名。
/*
SQL嵌套查询
******************/
单表查询的组合,省略。
SQL语句汇总
最新推荐文章于 2024-08-02 07:00:00 发布