sql 编程

@admin  January 17, 2017

今天研究了一个sql以后回来优化你

 

update tu_school_major_hot
set 
tu_school_major_hot.school_id = 
(
select tu_school.id as school_id 
from tu_school,tu_school_major  
where 
tu_school_major_hot.school_name = tu_school.en_school_name 
and 
tu_school_major_hot.major_name = tu_school_major.major_name 
and 
tu_school.en_school_name = tu_school_major.school_name 
limit 1
)  
,
tu_school_major_hot.category =  
(
select  tu_school_major.category 
from tu_school,tu_school_major  
where 
tu_school_major_hot.school_name = tu_school.en_school_name 
and 
tu_school_major_hot.major_name = tu_school_major.major_name 
and 
tu_school.en_school_name = tu_school_major.school_name 
limit 1
)   
,
tu_school_major_hot.major_id = 
(
select tu_school_major.id as major_id
from tu_school,tu_school_major  
where 
tu_school_major_hot.school_name = tu_school.en_school_name 
and 
tu_school_major_hot.major_name = tu_school_major.major_name 
and 
tu_school.en_school_name = tu_school_major.school_name 
limit 1
)  
WHERE
EXISTS 
(
select tu_school.id  
from tu_school,tu_school_major  
where 
tu_school_major_hot.school_name = tu_school.en_school_name 
and 
tu_school_major_hot.major_name = tu_school_major.major_name 
and 
tu_school.en_school_name = tu_school_major.school_name 
limit 1
)
;

添加新评论