gpt4 book ai didi

java - 如何合并两个查询的结果

转载 作者:行者123 更新时间:2023-11-30 01:09:02 25 4
gpt4 key购买 nike

我有一个类似的查询

SELECT class_id,student_id,title,location 
FROM class AS c
INNER JOIN library AS l
ON (l.student_id = c.student_id)
group by class_id,student_id;

输出:

class_id   student_id    title   location
1 mac smart 2ndfloor
1 john smart 2ndfloor
1 charles smart 2ndfloor
2 james hard 1stfloor

另一个查询

SELECT school_id,class_id,s.title FROM school

输出:

school_id class_id  title
1 1 school1
1 1 school1
1 2 school1

我必须先显示学校记录,然后显示该学校的类(class)(即)

 school_id   class_id  title 
1 NULL school //here school title and id
1 1 2ndfloor //here classes in that school
2 NuLL school2 //here next school title and id
2 1 2ndfloor //here classes in the next school

我怎样才能实现这个,请告诉我,它可以在mysql本身中完成,或者我需要使用java列表迭代器来迭代它。我正在使用mysql数据库和java。

最佳答案

您可以在 SQL 查询中使用 Union 来合并两个结果..

奥雷尔斯

在代码中,您可以使用一些父子 GridView 。

关于java - 如何合并两个查询的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19585797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com