Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to put several unrelated result sets together in mysql

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 226

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report