Get the App
SLTechnology News&Howtos  ›  Database  › 

How to put several unrelated result sets together in mysql

Shulou Source: shulou.com Published: 2022-05-31 18:00:16 09月16日 Update

This article mainly explains "how to put several unrelated result sets together in mysql". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to put several unrelated result sets together in mysql.

Solution:

Need to SELECT es.name primary_school, COUNT (DISTINCT esi.stu_id) primary_num FROM. , SELECT es.name AS high_school,COUNT (DISTINCT esi.stu_id) AS high_num FROM. , SELECT COUNT (DISTINCT esi.stu_id) total_num FROM. As there is no relationship between the results, add the number SELECT @ rownumb:=@rownumb+1 AS rownum, resources.* FROM (SELECT @ rownumb:=0) r, (… Resources, and then aggregate the three results according to the number:

SELECT c.rownum,b.high_school,b.high_num,a.primary_school,a.primary_num, c.total_num

FROM

(.) B

LEFT JOIN

(.) A

ON a.rownum = b.rownum

LEFT JOIN

(.) C

ON c.rownum = b.rownum

There is no problem with this result if there is a maximum number of rows in b, but the problem is that you do not know which one has the largest number of rows. To solve this problem, you can solve this problem directly by using full join, but full join is not available for the version used. The method is to use union all to combine the results obtained by several left join:

SELECT DISTINCT high_school,high_num,primary_school,primary_num, total_num

FROM

(SELECT c. Rownum. Highways. Highways. C.total_num.

FROM

(.) B

LEFT JOIN

(.) A

ON a.rownum = b.rownum

LEFT JOIN www.2cto.com

(.) C

ON c.rownum = b.rownum

UNION ALL

SELECT c.rownum,b.high_school,b.high_num,a.primary_school,a.primary_num, c.total_num

FROM

(.) A

LEFT JOIN

(.) B

ON a.rownum = b.rownum

LEFT JOIN

(.) C

ON c.rownum = a.rownum

) ee

At this point, I believe you have a deeper understanding of "how to put several unrelated result sets together in mysql". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Results methods questions content learning practical deeper nothing three between interest practicality practical easy to operate more friends version website channel query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi MariaDB Xiaomi Microsoft