2016-03-04 79 views
0

我有学生和班级。 每个学生有一个exam_place_id和教室 每个教室都有自己的坐位限制。 所以我必须根据学生的数量给予每个学生教室。如何给mysql数据库中限制人数赋予不同的值?

例如在伊斯坦布尔(exam_place_id = 11)我现在有530名学生。

和类配额就像

Class 1 - number of students can sit : 19 
Class 2 - number of students can sit : 26 
Class 3 - number of students can sit : 29 
Class 4 - number of students can sit : 24 
Class 5 - number of students can sit : 31 
Class 6 - number of students can sit : 22 
Class 7 - number of students can sit : 24 
Class 8 - number of students can sit : 29 
Class 9 - number of students can sit : 24 
Class 10 - number of students can sit : 25 
Class 11 - number of students can sit : 28 
Class 12 - number of students can sit : 24 
Class 13 - number of students can sit : 22 
Class 14 - number of students can sit : 28 
Class 15 - number of students can sit : 28 
Class 16 - number of students can sit : 27 
Class 17 - number of students can sit : 64 
Class 18 - number of students can sit : 64 

所以依班配额我会更新学生的班级

update students set class = "Class 1" where payStatus = 1 and is_completed = 1 and exam_place_id =11 and class = 0 limit 19 

update users set class = "Class 2" where payStatus = 1 and is_completed = 1 and exam_place_id =11 and class = 0 limit 26 

所以我会不会从表19级的用户,并检查他们的其中的类值为零(未定义)我将用我的班级号码更新它们。但没有工作它覆盖之前,即使我尝试更新学生与 class = 0

什么是我可以尝试的任何其他解决方案?

回答

1

据我们所知class列类型为varchar,所以0是不可能的值。您是否想要检查列值是否为NULL或为空?

UPDATE students SET class = "Class 1" 
WHERE payStatus = 1 AND is_completed = 1 AND 
     exam_place_id =11 AND (class IS NULL OR class = '') 
LIMIT 19 
1

也许这样的事情?

UPDATE TOP (19) users set class = "Class 2" where payStatus = 1 and is_completed = 1 and exam_place_id =11 and class = 0