首页 \ 问答 \ mysql在考试中获得学生排名(mysql get student rank in exam)

mysql在考试中获得学生排名(mysql get student rank in exam)

我有以下查询。

SELECT 
  SUM(
    marks_obtained_written + marks_obtained_oral + marks_obtained_classwork
  ),
  FIND_IN_SET(
    SUM(
      marks_obtained_written + marks_obtained_oral + marks_obtained_classwork
    ),
    (SELECT 
      GROUP_CONCAT(summarks 
        ORDER BY summarks DESC) 
    FROM
      (SELECT 
        SUM(
          marks_obtained_written + marks_obtained_oral + marks_obtained_classwork
        ) AS summarks 
      FROM
        results 
      GROUP BY student_id) sm)
  ) AS rank 
FROM
  results 
WHERE student_id = ".$student_id." 
  AND exam_year = ".$year." 
  AND exam_id = ".$exam." 
  AND results.class_id = ".$class_id." 
  AND section_id = ".$section_id." 

只有在我的结果表中有一个考试时,此查询才适用于我。 当有更多考试时,此查询会计算所有考试的分数并返回给我。 但是如果我只需要一个考试的学生排名,我需要在查询中放入exam_id,当我这样做时,查询返回0作为学生排名。

在此处输入图像描述

在上面的图片中,我得到了第0个无效的位置。但是如果我删除了exam_id条件,那么我得到了正确的等级,但问题是所有输入的考试的总和标记,我不想要因为我需要特定考试的等级。

所以请任何人告诉我应该在我的查询中放置exam_id条件。


I have the following query.

SELECT 
  SUM(
    marks_obtained_written + marks_obtained_oral + marks_obtained_classwork
  ),
  FIND_IN_SET(
    SUM(
      marks_obtained_written + marks_obtained_oral + marks_obtained_classwork
    ),
    (SELECT 
      GROUP_CONCAT(summarks 
        ORDER BY summarks DESC) 
    FROM
      (SELECT 
        SUM(
          marks_obtained_written + marks_obtained_oral + marks_obtained_classwork
        ) AS summarks 
      FROM
        results 
      GROUP BY student_id) sm)
  ) AS rank 
FROM
  results 
WHERE student_id = ".$student_id." 
  AND exam_year = ".$year." 
  AND exam_id = ".$exam." 
  AND results.class_id = ".$class_id." 
  AND section_id = ".$section_id." 

This query works fine for me only when there in one exam in my result table. When there are more exams,this query calculates marks for all exams and return rank to me. But In case I need student rank for only one exam, I need to put exam_id in the query and when I do that, the query returns 0 as student rank.

enter image description here

In above picture, I got 0th position which is invalid.But if i remove the exam_id condition,then I get the correct rank,but the problem is it sums marks for all entered exams which i dont want as I need rank for a specific exam.

So please anyone tell me where should I put the exam_id condition in my query.


原文:https://stackoverflow.com/questions/43178310
更新时间:2023-10-06 15:10

最满意答案

我真的找到答案。 我认为它更多的是一种解决方法,而不是一种解决方案,但它到底是什么。

我试图调试整个Dockerfile(一个接一个地注释掉一个命令),直到只剩下FROM和MAINTAINER。 我仍遇到同样的问题。

所以我将FROM图像更改为另一个图像,问题解决了。 基础图像超过9个月大,可能建立在一些旧版本之上,我不知道。

此处的解决方法只是更改FROM映像或(如果您有访问权限)重建它。

干杯!


I actually found answer. I think its more of a workaround than a solution, but what the hell.

I tried to debug the whole Dockerfile (commenting out one command after each other) till the point where I was left only with FROM and MAINTAINER. I was still running into the same issue.

So I changed FROM image to another and the problem was solved. The base image was more than 9 months old and probably built on some old version or something, I do not know.

The workaround here is just to change the FROM image or (if you have access) rebuild it.

Cheers!

相关问答

更多
  • 尝试改变 RUN ["./gradlew", "clean", "build", "--debug"] 至 RUN gradlew clean build --debug 对于RUN命令,不需要添加[,] 。 主要针对CMD, ENTRYPOINT 解决此问题的一般解决方案是进入系统进行调试 对于这种情况。 Removing intermediate container 02b237aa04c0 Step 3/4 : WORKDIR /app ---> e238b49f5174 <== useful ...
  • 此问题也在docker hub论坛上报告,并由docker hub团队解决。 标签现在正常显示。 https://hub.docker.com/r/stakater/base/tags/ The issue was reported on docker hub forum also, and it is resolved by docker hub team. The tags are showing properly now. https://hub.docker.com/r/stakater/base/ ...
  • 您可以直接使用Azure容器注册表webhooks ,简单的工作流程: 构建一个Web Api项目,通过Queue a build Rest API对每个详细请求(webhook请求)进行排队 创建Azure容器注册表webhook以调用Web API(步骤1) I choose option three. Therefore I set up a github repository with a one line Dockerfile: FROM alpine I used the alpine ima ...
  • 简短回答:配置书签名称就好像它们是标签一样,它应该可以工作。 较长的回答:从一些实验来看,截至2016年9月,似乎书签名称实际上与Docker Hub中配置的标签和分支版本相匹配。 但是,在推送书签更新时,只会自动触发与名称匹配的标记构建; 分支构建不会自动触发,但仍可以手动触发。 Short answer: Configure the bookmark names as if they were tags, and it should work. Longer answer: From some expe ...
  • 我已经联系了他们的支持团队,根据他们的回应,目前对自动构建的限制是: 2小时 2 GB RAM 1个CPU 30 GB磁盘空间 因此,对于较大的构建,您必须将它们分成由FROM语句和Repository Links连接的多个Automated Builds,或者在您的机器本地构建它们并将它们推送到存储库。 I've contacted their support team, and according to their response, the current limits on Automated Bu ...
  • 在错误输出中,它列出了ext_name的可能值。 mysql未列出。 有mysqli和pdo_mysql ,但不是mysql 。 你的命令确实包含了mysql ,错误的第一行似乎在抱怨。 尝试解决这个问题,看看是否有效。 In the error output, it lists the possible values for ext_name. mysql isn't listed. There is mysqli and pdo_mysql, but not mysql. Your command do ...
  • 因为你是crosspost,我crossanswer:P恕我直言交叉错误,你应该删除其中一个问题。 这个问题也在这里得到解答(因为你已经找到了我的github bug报告): https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23529 目前,在emacs构建系统发生变化之前,可能会出现这种情况,唯一有效的解决方案是: 不要使用Dockerfile构建并构建一个运行容器,该容器具有允许个性系统调用的seccomp配置文件。 例如: docker run --rm - ...
  • 您不必将postgres二进制文件和数据放在同一个容器中。 pg_config基本上是配置你的postgres。 pg_config在postgresql-devel (Debian / Ubuntu中的libpq-dev ) 在本质上: # container were your data is docker run -d --name openproject-postgres-data -v /data busybox true # container were postgres runs docker ...
  • 我真的找到答案。 我认为它更多的是一种解决方法,而不是一种解决方案,但它到底是什么。 我试图调试整个Dockerfile(一个接一个地注释掉一个命令),直到只剩下FROM和MAINTAINER。 我仍遇到同样的问题。 所以我将FROM图像更改为另一个图像,问题解决了。 基础图像超过9个月大,可能建立在一些旧版本之上,我不知道。 此处的解决方法只是更改FROM映像或(如果您有访问权限)重建它。 干杯! I actually found answer. I think its more of a workaro ...
  • 我终于弄明白了。 这个问题与这个问题有关。 我在我的主机中使用Docker 1.0,但后来的版本在Docker Hub中正在生产中。 如果Dockerfile中没有明确的ENV HOME=...行,则版本1.0使用/作为主目录,而/root用于更高版本。 结果是vim无法找到它的.vimrc文件,因为它被复制到/而不是/root 。 我使用的解决方案是在我的Dockerfile中明确定义ENV HOME=/root ,因此两个版本之间没有区别。 I finally figured it out. The i ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)