按数据顺序提取不同ResultSet的结果

时间:2020-12-30 15:40:17

i have 4 ResultSet obtained by for 4 differents queries. I would to create a JSON object with the attribues of these differents ResultSets merged ordered by a parameter of each record having a Datetime type.

我有4个不同的查询获得4个ResultSet。我想创建一个JSON对象,其中包含这些不同的属性ResultSets合并由具有Datetime类型的每个记录的参数排序。

Suppose this case:

假设这种情况:

ResultSet rs1 = from query ("select a, date from table order by date");
ResultSet rs2 = from query ("select b, c, date from table1 order by date");
ResultSet rs3 = from query ("select d, e, f, date from table2 order by date");
ResultSet rs4 = from query ("select g, h, i, l, date from table3 order by date");

As you can see above, the ResultSets have differents extracted fields, different number of extracted fields etc..the only common info is the field "data" that is present in all the ResultSed as LAST FIELD (LAST INDEX OF THE QUERIES).

正如您在上面所看到的,ResultSet有不同的提取字段,不同数量的提取字段等。唯一的常见信息是所有ResultSed中存在的字段“data”作为LAST FIELD(最后的查询索引)。

Then I would to obtain a JSON like this: note that the object with minor index is the most recent, the object with last index is the oldest considering "data" field

然后我会得到这样的JSON:请注意,具有次要索引的对象是最新的,具有最后索引的对象是考虑到“数据”字段的最旧对象

{"numberObjects":5,
a1:"valuea1",
data1:"valueDataa1",
d2:"valued2",
e2:"valuee2",
f2:"valuef2",
...}

There is a way to do this thing? The only procedure that i know is very very laboriuous so i ask you if oyu know a way faster and easier to actuate this thing..thanks to all.

有办法做这件事吗?我知道的唯一一个程序是非常非常劳动,所以我问你oyu是否知道更快更方便地启动这个东西..谢谢所有人。

1 个解决方案

#1


1  

You can use a compound query to sort everything at once; this requires that the component queries return the same number of columns:

您可以使用复合查询一次对所有内容进行排序;这要求组件查询返回相同数量的列:

SELECT a, NULL, NULL, NULL, date FROM tab1
UNION ALL
SELECT b, c, d, e, date FROM tab2
UNION ALL
SELECT ...
ORDER BY date;

#1


1  

You can use a compound query to sort everything at once; this requires that the component queries return the same number of columns:

您可以使用复合查询一次对所有内容进行排序;这要求组件查询返回相同数量的列:

SELECT a, NULL, NULL, NULL, date FROM tab1
UNION ALL
SELECT b, c, d, e, date FROM tab2
UNION ALL
SELECT ...
ORDER BY date;