1. 程式人生 > 其它 >js 拖拽元件sortablejs的簡單使用

js 拖拽元件sortablejs的簡單使用

先給出需求,有2張表,學生表和分數表,兩種表都有一個分數列,但是這兩列的值不一致,現在需要更新學生表,讓學生表中的值等於分數表中的值。
初始化指令碼如下:

create table student
(
  id varchar(100) primary key,
  name varchar(50),
  addr varchar(50),
  score int
);

create table score
(
  stuId varchar(100) primary key,
  score int
);

insert into student(id,name,addr,score) values('1','張三','重慶',100);
insert into student(id,name,addr,score) values('2','張三2','重慶',120);
insert into student(id,name,addr,score) values('3','張三3','重慶',150);

insert into score(stuId,score) values('1',10);
insert into score(stuId,score) values('2',12);
insert into score(stuId,score) values('4',50);

資料展示如下:

   

 

mysql更新指令碼:

update student a inner join score b on a.id=b.stuId set a.score=b.score;

oracle更新指令碼:

-- 方式一
UPDATE (
select t1.score t1score,t2.score t2score from student t1 inner join score t2 on t1.id=t2.stuId
)t
set t1score =t2score;

-- 方式二
merge into student
using (select stuId,score from score) t
on (t.stuId = student.id)
when matched then 
  update set student.score = t.score;

Sqlserver更新指令碼: 

update a set a.score=b.score from student a inner join score b on a.id=b.stuId;