sql选择每个stundents的最后记录笔记

时间:2021-07-20 12:49:44

I have this table notes.data of my table note and i want to select last notes for each subject(matiere) and for each students(id_etudiant). please help me with my sql code. In short i want result like this result

我有这张表笔记。我的表笔记的数据。我想为每个主题(matiere)和每个学生(id_etudiant)选择最后的笔记。请帮我解决我的sql代码。总之,我想要这样的结果

3 个解决方案

#1


0  

You can try query like this

您可以尝试这样的查询

SELECT * FROM table_name GROUP BY id_etudiant,id_matiere ORDER BY cod_note desc 

#2


0  

i will explain. i have a table "notes" like this:

我会解释。我有一个像这样的表“笔记”:

code id id_sub id_unit notes session year
1 BEE12 1 1 10.00 normale 2017
2 ABHA 1 1 9.00 normale 2017
3 BEE12 2 1 13.00 normale 2017
4 ABHA 2 1 10.00 normale 2017
5 ABHA 1 1 19.00 rattrapage 2017

代码id id_sub id_unit notes会话年1 BEE12 1 1 10.00 normale 2017 2 ABHA 1 1 9.00 normale 2017 3 BEE12 2 1 13.00 normale 2017 4 ABHA 2 1 10.00 normale 2017 5 ABHA 1 1 19.00 rattrapage 2017

but i need a query who return this:

但我需要一个返回此查询的查询:

code id id_sub id_unit notes session year
1 BEE12 1 1 10.00 normale 2017
3 BEE12 2 1 13.00 normale 2017
4 ABHA 2 1 10.00 normale 2017
5 ABHA 1 1 19.00 rattrapage 2017

代码id id_sub id_unit notes会话年1 BEE12 1 1 10.00 normale 2017 3 BEE12 2 1 13.00 normale 2017 4 ABHA 2 1 10.00 normale 2017 5 ABHA 1 1 19.00 rattrapage 2017

I use this query now:
select n1.* from notes n1 left join notes n2 ON (n1.id= n2.id and n1.id_sub=n2.id_sub and n1.code < n2.code) where n2.code is null;

我现在使用这个查询:从注释n1中选择n1。*左连接注释n2 ON(n1.id = n2.id和n1.id_sub = n2.id_sub和n1.code )其中n2.code为null;

#3


0  

it's very simple. select is used to display content, So whatever you want to be displayed first we can alter that by using order by with that coloumn and sort data in ascending or descending order.

这很简单。 select用于显示内容,因此无论您希望首先显示什么,我们都可以通过使用该coloumn并按升序或降序排序数据来改变它。

try query:

select * from table_name order by id DESC

通过id DESC从table_name顺序中选择*

#1


0  

You can try query like this

您可以尝试这样的查询

SELECT * FROM table_name GROUP BY id_etudiant,id_matiere ORDER BY cod_note desc 

#2


0  

i will explain. i have a table "notes" like this:

我会解释。我有一个像这样的表“笔记”:

code id id_sub id_unit notes session year
1 BEE12 1 1 10.00 normale 2017
2 ABHA 1 1 9.00 normale 2017
3 BEE12 2 1 13.00 normale 2017
4 ABHA 2 1 10.00 normale 2017
5 ABHA 1 1 19.00 rattrapage 2017

代码id id_sub id_unit notes会话年1 BEE12 1 1 10.00 normale 2017 2 ABHA 1 1 9.00 normale 2017 3 BEE12 2 1 13.00 normale 2017 4 ABHA 2 1 10.00 normale 2017 5 ABHA 1 1 19.00 rattrapage 2017

but i need a query who return this:

但我需要一个返回此查询的查询:

code id id_sub id_unit notes session year
1 BEE12 1 1 10.00 normale 2017
3 BEE12 2 1 13.00 normale 2017
4 ABHA 2 1 10.00 normale 2017
5 ABHA 1 1 19.00 rattrapage 2017

代码id id_sub id_unit notes会话年1 BEE12 1 1 10.00 normale 2017 3 BEE12 2 1 13.00 normale 2017 4 ABHA 2 1 10.00 normale 2017 5 ABHA 1 1 19.00 rattrapage 2017

I use this query now:
select n1.* from notes n1 left join notes n2 ON (n1.id= n2.id and n1.id_sub=n2.id_sub and n1.code < n2.code) where n2.code is null;

我现在使用这个查询:从注释n1中选择n1。*左连接注释n2 ON(n1.id = n2.id和n1.id_sub = n2.id_sub和n1.code )其中n2.code为null;

#3


0  

it's very simple. select is used to display content, So whatever you want to be displayed first we can alter that by using order by with that coloumn and sort data in ascending or descending order.

这很简单。 select用于显示内容,因此无论您希望首先显示什么,我们都可以通过使用该coloumn并按升序或降序排序数据来改变它。

try query:

select * from table_name order by id DESC

通过id DESC从table_name顺序中选择*