如何从表中获得最低和最高的学生ID [英] How to get lowest and highest student Id from a table

查看:97
本文介绍了如何从表中获得最低和最高的学生ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下结构和数据的表格



Class Studentid



1 1

1 2

1 3

1 4

1 5



2 1

2 2

2 3



3 1
3 2

3 3

3 4



4 1



5 1

5 2



我需要取结果最低的学生ID以及最高的学生ID如下

Class Studentid



1 1

1 5



2 1

2 3



3 1

3 4



4 1



5 1

5 2

I have a table with the following structure and with the data

Class Studentid

1 1
1 2
1 3
1 4
1 5

2 1
2 2
2 3

3 1
3 2
3 3
3 4

4 1

5 1
5 2

I need to take the result The the lowest student id and the highest student id as follow as
Class Studentid

1 1
1 5

2 1
2 3

3 1
3 4

4 1

5 1
5 2

推荐答案

嗨Sacraj,



我创建了一个架构,你可以以下查询获取记录

Hi Sacraj,

I have created a schema and you could use the below query to get the records
create table sellowhigh(class int,ranks int)
insert into sellowhigh values(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,4),(3,1),(3,2),(3,3),(3,7),(4,2),(4,3),(4,5),(4,8)
select * from sellowhigh

select class,min(ranks)as ranks from sellowhigh group by class union
select class,max(ranks)as ranks from sellowhigh group by class





班级 等级

1 1

1 4

2 1

2 4

3 1

3 7

4 2

4 8



我希望这会对你有所帮助。



问候,

RK



class Ranks
1 1
1 4
2 1
2 4
3 1
3 7
4 2
4 8

I hope this helps you a bit.

Regards,
RK


这篇关于如何从表中获得最低和最高的学生ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆