mysql> SELECT 3/5; -> 0.60Division by zero produces a NULL result: mysql> SELECT 102/(1-1); -> NULLA division is calculated with BIGINT arithmetic only if performed in a context where its result is converted to an integer. DIV
Integer division. Similar to FLOOR(), but is safe with BIGINT values. Incorrect results may occur for non-integer operands that exceed BIGINT range. mysql> SELECT 5 DIV 2; -> 2
就是除法 一个是数学运算 商是double的 一个是int的 div mysql相当于floor division是一门运算 不知道数据库系统基础里面怎么说
注意: 复杂点说就是 (R) 包括所有 (S) 中记录的那些项目。(可惜很少有数据支持这个除法目前我用的数据库还没有支持这个 关系代数除法的。 只能通过其它方法来得到相同的结果。但只是实现相同的结果,在关系代数上已经用了不同的算法了。转换谓词语义为找出 不存在这么一门课程这个学生没有选 select * from student where not exist (select courseid from course where courseid not in (select courseid from sc where studentid =student .student id))
Division:
mysql> SELECT 3/5;
-> 0.60Division by zero produces a NULL result: mysql> SELECT 102/(1-1);
-> NULLA division is calculated with BIGINT arithmetic only if performed in a context where its result is converted to an integer. DIV
Integer division. Similar to FLOOR(), but is safe with BIGINT values. Incorrect results may occur for non-integer operands that exceed BIGINT range. mysql> SELECT 5 DIV 2;
-> 2
一个是数学运算 商是double的
一个是int的 div mysql相当于floor
division是一门运算 不知道数据库系统基础里面怎么说
也是啊!其实是关系代数里的概念!
这两天看《数据库系统基础-基础篇》中的内容,第六章 关系代数和关系演算中,讲完了select, project,union,minus以及笛卡尔积等一系列对关系操作后,又引出了关系的division(除)操作!
并给了个例子,检索‘john smith’参与的所有工作项目中的所有雇员的姓名. 这当中用到了division操作!不知道说清楚没有!不是数与数之间的除法,是关系运算中的除!
鉴于版主提供的维基百科上的这个例子,我想用sql语句来模拟实现一下,不过不清楚减法操作如何实现.
模拟如下:CREATE TABLE R(Student VARCHAR(16), Task VARCHAR(16));
INSERT INTO R(Student, Task) VALUES
('Fred', 'Database1'),
('Fred', 'Database2'),
('Fred', 'Compiler1'),
('Eugene', 'Database1'),
('Eugene', 'Compiler1'),
('Sara', 'Database1'),
('Sara', 'Database2');CREATE TABLE S(Task VARCHAR(16));
INSERT INTO S(Task) VALUES('Database1'), ('Database2'); CREATE TABLE T SELECT * FROM (SELECT DISTINCT Student FROM R) tmp JOIN S; //投影Student于R,然后与S进行笛卡尔积得到关系T.
紧接着就是需要T - R,用sql语句如何做到呢?
注意: 复杂点说就是 (R) 包括所有 (S) 中记录的那些项目。(可惜很少有数据支持这个除法目前我用的数据库还没有支持这个 关系代数除法的。
只能通过其它方法来得到相同的结果。但只是实现相同的结果,在关系代数上已经用了不同的算法了。转换谓词语义为找出 不存在这么一门课程这个学生没有选
select * from student where not exist (select courseid from course where courseid not in (select courseid from sc where studentid =student .student id))