SELECT 班别,姓名,成绩 FROM T1 ;
JOIN (SELECT 班别 班级1,MAX(成绩) 成绩1 ;
FROM T1 GROUP BY 班级1) T2 ;
ON 班别=班级1 AND 成绩=成绩1 ;
UNION ALL ;
SELECT 班别,姓名,成绩 FROM T1 ;
JOIN (SELECT 班别 班级2,MAX(成绩) 成绩2 ;
FROM T1 ;
JOIN (SELECT 班别 班级1,MAX(成绩) 成绩1 ;
FROM T1 GROUP BY 班级1) T2 ;
ON 班别=班级1 AND 成绩<成绩1 ;
GROUP BY 班别) T3 ;
ON 班别=班级2 AND 成绩=成绩2 ;
UNION ALL ;
SELECT 班别,姓名,成绩 FROM T1 ;
JOIN (SELECT 班别 班级3,MAX(成绩) 成绩3 ;
FROM T1 ;
JOIN (SELECT 班别 班级2,MAX(成绩) 成绩2 ;
FROM T1 ;
JOIN (SELECT 班别 班级1,MAX(成绩) 成绩1 ;
FROM T1 GROUP BY 班级1) T2 ;
ON 班别=班级1 AND 成绩<成绩1 ;
GROUP BY 班别) T3 ;
ON 班别=班级2 AND 成绩<成绩2 ;
GROUP BY 班别) T4 ;
ON 班别=班级3 AND 成绩=成绩3 ;
ORDER BY 班别,成绩 DESC,姓名
CLOSE DATABASES
USE cj IN 0
SELECT * FROM cj INTO CURSOR 查询结果表 READWRITE WHERE .f.
SELECT distinct 班别 FROM CJ INTO CURSOR cj_tmp2
SELECT cj_tmp2
SCAN
INSERT INTO 查询结果表 (班别,姓名,成绩) SELECT TOP 3 班别,姓名,成绩 FROM cj WHERE 班别==cj_tmp2.班别 ORDER BY 成绩 DESC
ENDSCAN
SELECT 查询结果表
BROWSE
CLOSE DATABASES
*假设你的数据表名称为T.DBF
SELECT * FROM T WHERE .F. INTO CURSOR T2 READWRITE
SELECT BJ FROM T GROUP BY BJ INTO CURSOR T1
SELECT T1
SCAN
INSERT INTO T2 SELECT TOP 3 BJ,XM,CJ FROM T ORDER BY BJ ,CJ DESC WHERE BJ=T1.BJ
ENDSCAN
SELECT T2 &&查询结果表
BROWSE