mysql - SQL操作数执行单行、列

标签 mysql sql

enter image description here 我的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'

在此查询中,我想输入多个subjectidregnos来获取数据
谁能帮我解决这个问题。

最佳答案

您可以使用 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'

关于mysql - SQL操作数执行单行、列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44947006/

相关文章:

mysql - 如何将 mysql 查询转换为事务 SQL 查询

mysql - 每行 SQL 的一些变量

sql - 选择仅出现在一个位置 ID 中的手机号码

sql - 在 AREL 中分组 ands 和 ors

sql - 使用筛选行比较排除约束

sql - 获取有条件的数据

php - 使用file_exists并更新mysql行

PHP 安全地登录到 mysql 但如果失败则继续脚本

mysql - SQL 连接返回错误表中的所有值

mysql - LIKE MySQL 搜索无法使用 CONCAT