我有一个包含表的数据库。
create table student (
stu_code integer,
stu_name varchar(32),
primary key (stu_code)
)
create table teacher (
tea_code integer not null,
tea_name varchar(25),
primary key (tea_code)
)
create table course (
cor_code integer not null,
cor_name varchar(32),
salary float(32),
unit integer,
primary key (cor_code)
)
create table term (
stu_code integer,
cor_code integer,
tea_code integer,
grade decimal(25),
year integer,
)
我已经手动填写了三个表格。
术语表是由 Javascript 代码生成的:
<html>
<body>
<div id="rnd"></div>
<script type="text/javascript">
function rnd(a,b){
return Math.floor(Math.random()*(b-a+1))+a;
}
for (var i=0;i<600;i++) {
var stu = rnd(41,49),
cor = rnd(10,26),
tea = rnd(81,90),
year = rnd(1391,1392),
grade = rnd(8,20);
(year==1392)?grade = null:true;
document.writeln(
"insert into term (stu_code,cor_code,tea_code,grade,year) values "
+"(884221" +stu+","
+"180" +cor+","
+"15120" +tea+","
+grade +","
+year
+");"
+"<br>"
);
}
</script>
</body>
</html>
我的问题是术语表中有额外的行。
如何集成/删除其他行?
有没有办法在没有额外随机行的情况下填充表格?
/* 更新 : */
例如 :
insert into term (s,c,t,g) values (45,16,88,16,91);
insert into term (s,c,t,g) values (45,16,86,10,91);
insert into term (s,c,t,g) values (45,16,87,8,91);
insert into term (s,c,t,g) values (41,15,85,20,91);
insert into term (s,c,t,g) values (41,15,88,17,91);
现在我想显示:
insert into term (s,c,t,g) values (45,16,88,16,91);
insert into term (s,c,t,g) values (41,15,85,20,91);
or
insert into term (s,c,t,g) values (45,16,88,16,91);
insert into term (s,c,t,g) values (41,15,88,17,91);
or
insert into term (s,c,t,g) values (45,16,86,10,91);
insert into term (s,c,t,g) values (41,15,85,20,91);
or
insert into term (s,c,t,g) values (45,16,86,10,91);
insert into term (s,c,t,g) values (41,15,88,17,91);
or
insert into term (s,c,t,g) values (45,16,87,8,91);
insert into term (s,c,t,g) values (41,15,85,20,91);
or
insert into term (s,c,t,g) values (45,16,87,8,91);
insert into term (s,c,t,g) values (41,15,88,17,91);
/*结束更新*/
/* 再次更新 */
我可以在 Sql Server 中编写代码 但是这段代码在 Mysql 中不起作用,为什么?Mysql中这段代码的等价物是什么?
delete from term
where stu_code in(
select stu_code
from term
group by stu_code,cod_code,year
having COUNT(stu_code)>=2
/* 结束最后一次更新 */
请帮我解决这个问题!
谢谢:x