Home >Database >Mysql Tutorial >提取表中每个分组的前几条数据

提取表中每个分组的前几条数据

WBOY
WBOYOriginal
2016-06-07 14:53:431096browse

提取表中每个分组的前几条数据 SELECT 课程, SUM(奖金) AS 奖金 FROM ( SELECT 课程, 学号, 成绩 FROM 考试 AS a WHERE ( SELECT COUNT(*) FROM 考试 WHERE 课程 = a.课程 AND 学号 a.学号 AND 成绩 a.成绩 ) 3 www.2cto.com ) AS b GROUP BY 课程


提取表中每个分组的前几条数据

 

SELECT  课程,

        SUM(奖金) AS 奖金

FROM    ( SELECT    课程,

                    学号,

                    成绩

          FROM      考试 AS a

          WHERE     ( SELECT    COUNT(*)

                      FROM      考试

                      WHERE     课程 = a.课程

                                AND 学号 a.学号

                                AND 成绩 > a.成绩

                    )

        ) AS b

GROUP BY 课程
 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn