求最简语句,不用子查询能否实现
13 个解决方案
#1
1、将表、记录及要求结果贴出来看看;
2、TRY:
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (SELECT XH,MAX(CJ) FROM 各班级程绩 GROUP BY XH) B
ON A.XH=B.XH
2、TRY:
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (SELECT XH,MAX(CJ) FROM 各班级程绩 GROUP BY XH) B
ON A.XH=B.XH
#2
select student_grade,student_id ,max(student_mark) from mark
group by student_grade,student_id
group by student_grade,student_id
#3
TRY:
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (
SELECT * FROM 各班级程绩 A INNER JOIN
(SELECT BJ,MAX(CJ) AS CJ1 FROM 各班级程绩 GROUP BY BJ) B
ON A.CJ=B.CJ1
) B
ON A.XH=B.XH
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (
SELECT * FROM 各班级程绩 A INNER JOIN
(SELECT BJ,MAX(CJ) AS CJ1 FROM 各班级程绩 GROUP BY BJ) B
ON A.CJ=B.CJ1
) B
ON A.XH=B.XH
#4
楼上是RIGHT JOIN吧,这样是可以,如果不用子查询,能实现么
把问题再写一下:
原表: 1.1 tom 100 boy
1.1 ros 99 girl
1.2 mik 90 boy
1.2 sha 95 girl
结果 1.1 tom 100 boy
1.2 sha 95 girl
即:各班取程绩最高者的记录
把问题再写一下:
原表: 1.1 tom 100 boy
1.1 ros 99 girl
1.2 mik 90 boy
1.2 sha 95 girl
结果 1.1 tom 100 boy
1.2 sha 95 girl
即:各班取程绩最高者的记录
#5
1、SELECT * FROM TT A WHERE FS=(SELECT TOP 1 FS FROM TT WHERE
A.KC=B.KC ORDER BY FS DESC)
FS:分数 KC:1.1 OR 1.2
2、SELECT A.* FROM TT A INNER JOIN
(SELECT KC,MAX(FS) AS MFS FROM TT GROUP BY KC) B
ON A.FS=B.MFS AND A.KC=B.KC
A.KC=B.KC ORDER BY FS DESC)
FS:分数 KC:1.1 OR 1.2
2、SELECT A.* FROM TT A INNER JOIN
(SELECT KC,MAX(FS) AS MFS FROM TT GROUP BY KC) B
ON A.FS=B.MFS AND A.KC=B.KC
#6
1、
SELECT *
FROM PPY AS A
WHERE FS=(SELECT TOP 1 FS FROM PPY WHERE A.KC=KC ORDER BY FS DESC);
2、
SELECT A.*
FROM PPY AS A INNER JOIN (SELECT KC,MAX(FS) AS MFS FROM PPY GROUP BY KC) AS B ON (A.KC=B.KC) AND (A.FS=B.MFS);
ppy为表名,你可以自行修改
SELECT *
FROM PPY AS A
WHERE FS=(SELECT TOP 1 FS FROM PPY WHERE A.KC=KC ORDER BY FS DESC);
2、
SELECT A.*
FROM PPY AS A INNER JOIN (SELECT KC,MAX(FS) AS MFS FROM PPY GROUP BY KC) AS B ON (A.KC=B.KC) AND (A.FS=B.MFS);
ppy为表名,你可以自行修改
#7
好快,谢谢鸟~~
#8
看来只能选筛出最大的,再连接了,用子查询
#9
看来只能选筛出最大的,再连接了,用子查询
NO,可以用DMAX,不过速度比较慢。
NO,可以用DMAX,不过速度比较慢。
#10
哦!!,能给个例子么
#11
SELECT * from ppy a where fs=dmax("fs","ppy","kc=" & a.kc )
如KC为数字型
如KC为数字型
#12
如KC为字符型
SELECT * from ppy a where fs=dmax("fs","ppy","kc='" & a.kc &"'")
SELECT * from ppy a where fs=dmax("fs","ppy","kc='" & a.kc &"'")
#13
这种方法还真不知道,多谢!
#1
1、将表、记录及要求结果贴出来看看;
2、TRY:
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (SELECT XH,MAX(CJ) FROM 各班级程绩 GROUP BY XH) B
ON A.XH=B.XH
2、TRY:
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (SELECT XH,MAX(CJ) FROM 各班级程绩 GROUP BY XH) B
ON A.XH=B.XH
#2
select student_grade,student_id ,max(student_mark) from mark
group by student_grade,student_id
group by student_grade,student_id
#3
TRY:
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (
SELECT * FROM 各班级程绩 A INNER JOIN
(SELECT BJ,MAX(CJ) AS CJ1 FROM 各班级程绩 GROUP BY BJ) B
ON A.CJ=B.CJ1
) B
ON A.XH=B.XH
SELECT A.* FROM 某学校学生信息表 A
LEFT JOIN (
SELECT * FROM 各班级程绩 A INNER JOIN
(SELECT BJ,MAX(CJ) AS CJ1 FROM 各班级程绩 GROUP BY BJ) B
ON A.CJ=B.CJ1
) B
ON A.XH=B.XH
#4
楼上是RIGHT JOIN吧,这样是可以,如果不用子查询,能实现么
把问题再写一下:
原表: 1.1 tom 100 boy
1.1 ros 99 girl
1.2 mik 90 boy
1.2 sha 95 girl
结果 1.1 tom 100 boy
1.2 sha 95 girl
即:各班取程绩最高者的记录
把问题再写一下:
原表: 1.1 tom 100 boy
1.1 ros 99 girl
1.2 mik 90 boy
1.2 sha 95 girl
结果 1.1 tom 100 boy
1.2 sha 95 girl
即:各班取程绩最高者的记录
#5
1、SELECT * FROM TT A WHERE FS=(SELECT TOP 1 FS FROM TT WHERE
A.KC=B.KC ORDER BY FS DESC)
FS:分数 KC:1.1 OR 1.2
2、SELECT A.* FROM TT A INNER JOIN
(SELECT KC,MAX(FS) AS MFS FROM TT GROUP BY KC) B
ON A.FS=B.MFS AND A.KC=B.KC
A.KC=B.KC ORDER BY FS DESC)
FS:分数 KC:1.1 OR 1.2
2、SELECT A.* FROM TT A INNER JOIN
(SELECT KC,MAX(FS) AS MFS FROM TT GROUP BY KC) B
ON A.FS=B.MFS AND A.KC=B.KC
#6
1、
SELECT *
FROM PPY AS A
WHERE FS=(SELECT TOP 1 FS FROM PPY WHERE A.KC=KC ORDER BY FS DESC);
2、
SELECT A.*
FROM PPY AS A INNER JOIN (SELECT KC,MAX(FS) AS MFS FROM PPY GROUP BY KC) AS B ON (A.KC=B.KC) AND (A.FS=B.MFS);
ppy为表名,你可以自行修改
SELECT *
FROM PPY AS A
WHERE FS=(SELECT TOP 1 FS FROM PPY WHERE A.KC=KC ORDER BY FS DESC);
2、
SELECT A.*
FROM PPY AS A INNER JOIN (SELECT KC,MAX(FS) AS MFS FROM PPY GROUP BY KC) AS B ON (A.KC=B.KC) AND (A.FS=B.MFS);
ppy为表名,你可以自行修改
#7
好快,谢谢鸟~~
#8
看来只能选筛出最大的,再连接了,用子查询
#9
看来只能选筛出最大的,再连接了,用子查询
NO,可以用DMAX,不过速度比较慢。
NO,可以用DMAX,不过速度比较慢。
#10
哦!!,能给个例子么
#11
SELECT * from ppy a where fs=dmax("fs","ppy","kc=" & a.kc )
如KC为数字型
如KC为数字型
#12
如KC为字符型
SELECT * from ppy a where fs=dmax("fs","ppy","kc='" & a.kc &"'")
SELECT * from ppy a where fs=dmax("fs","ppy","kc='" & a.kc &"'")
#13
这种方法还真不知道,多谢!