摘要:
学生表:ssid sname1 s12 s23 s3课程表:ccid cname1 c12 c2选课表:scsid cid1 12 11 2查询选修了课程的学生:select * from s where exists(select * from sc where s.sid=sid)exists查询过程:先执行主查询, select * from s , 然后用主查询的每一条记录的sid与表sc中的sid作相等比较(如果与选课表第一条记录不相等,则继续往下查找,如果找到,就不往下查找了,找到返回true,没有找到则返回false),如果相等,返回真, 就筛选出这条记录.ex... 阅读全文
摘要:
内连接 外连接 全连接 交叉连接 自身连接:内连接:有三种写法.1. select * from A,B where A.id=B.id 这是我们平时用得最多的.(WHERE子句中使用的连接语句,在数据库语言中,被称为隐性连接。INNER JOIN……ON子句产生的连接称为显性连接。(其他JOIN参数也是显性连接)WHERE 和INNER JOIN产生的连接关系,没有本质区别,结果也一样。但是!隐性连接随着数据库语言的规范和发展,已经逐渐被淘汰,比较新的数据库语言基本上已经抛弃了隐性连接,全部采用显性连接了。)2. select * from A join B on A.id=B.id3. s 阅读全文
摘要:
1select * from tbuser where username is not null 不能:username=nullselect * from tbuser where usernameis null2select merchanttypeid, COUNT(integral) from tbmerchantinfo错误:选择列表中的列 'tbmerchantinfo.merchanttypeid' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。select count(integral) from tbmerchantinfo 是可以的.正确:s 阅读全文