我想从仅属于类rows最后一行的class表中获取3个5,6 and 7数据。
现在,我正在使用3个sql查询来获取数据:
1. SELECT * from class where class_name = '5';
2. SELECT * from class where class_name = '6';
3. SELECT * from class where class_name = '7';如何使用单个sql查询来检索3行数据而不是3次sql查询?
**class table structure:**
|id | class_name | student |
|---| -----------| ---------|
|1 | 5 | Student A|
|2 | 6 | Student B|
|3 | 4 | Student C|
|4 | 6 | Student D|
|5 | 7 | Student E|
|6 | 5 | Student F|
|7 | 4 | Student G|
|8 | 6 | Student H|
|9 | 5 | Student I|
|10 | 6 | Student J|
|11 | 7 | Student K|
|12 | 6 | Student L|
|13 | 8 | Student M|
|14 | 6 | Student N|
|15 | 8 | Student O|成绩要求:学生I,学生N和学生K
发布于 2017-06-07 06:01:05
尝尝这个
SELECT * FROM class WHERE id IN (SELECT MAX(id) FROM class WHERE class_name in (5,6,7) GROUP BY class_name );木琴
发布于 2017-06-07 05:59:29
select * from (select * from class order by id desc, class_name) x group by class_name
发布于 2017-06-07 06:18:41
SELECT * from (SELECT * from class ORDER BY id DESC) t WHERE class_name in (5,6,7) GROUP BY class_name ORDER BY id DESC https://stackoverflow.com/questions/44404585
复制相似问题