2017-07-06 54 views
0

enter image description here我的SQL查询: -SQL操作进行单列,列

SELECT 
(s.Mark*0.8+((i.OutOf)*sum(i.Mark)/9000)+((ai.OutOf)*sum(ai.Mark) /180)+a.Mark) 
AS final 
from mark_semester s, 
    mark_assignment ai, 
    mark_internaltest i, 
    mark_attendance a, 
    master_student ms 
WHERE s.SubjectId=i.SubjectId and 
     s.SubjectId=ai.SubjectId 
     and s.SubjectId=a.SubjectId 
     and s.SubjectId='1' 
     AND s.RegNo=i.RegNo 
     and s.RegNo=ai.RegNo 
     and s.RegNo=a.RegNo 
     and s.RegNo=ms.RegNo 
     and s.RegNo='100' 
     and s.Semester=i.Semester 
     and s.Semester=ai.Semester 
     and s.Semester=a.Semester 
     and s.Semester='1' 

在此查询我要输入多个subjectidsregnos获取数据
任何一个可以帮助我解决这个问题。

+1

(1)*不要*的'FROM'子句中使用逗号。 *总是*使用正确的,明确的'JOIN'语法。 (2)我删除了不兼容的数据库标签。 (3)你没有问题。 –

+0

ü可以给我修改后的查询,请 –

+1

可以使用IN子句s.SubjectId在(“1”,“2”,3' )和同为REGNO的 –

回答

1

可以使用IN MySQL的操作来处理多个SubjectIdRegNo,像这样:

SELECT (s.Mark*0.8+((i.OutOf)*sum(i.Mark)/9000)+((ai.OutOf)*sum(ai.Mark)/180)+a.Mark) AS final 
from mark_semester s 
    join mark_assignment ai on s.SubjectId=ai.SubjectId 
    join mark_internaltest i on s.SubjectId=i.SubjectId 
    join mark_attendance a on s.SubjectId=a.SubjectId 
    join master_student ms on s.RegNo=ms.RegNo 
WHERE 
    s.SubjectId in ('1','2') AND 
    s.RegNo in ('100','101') and 
    s.Semester='1' 
+0

兄弟这个代码是很好的优化的一个上线4和5小的修正 –

+0

是它的工作对你(不要标记不参与产品。)? –

+0

是只得到一个行和列asusual –