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

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

WBOY
Release: 2016-06-07 14:53:43
Original
1099 people have browsed it

提取表中每个分组的前几条数据 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 课程
 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template