Home > database >  Bosses, can you tell me the two tables in the same field how to merge grouping statistics
Bosses, can you tell me the two tables in the same field how to merge grouping statistics

Time:10-11

Bosses, such as
The first table SQL:
 SELECT count (*) as the count, stage FROM ` gametext ` WHERE ` status `=0 AND ` isEgg `=0 AND ` stage ` & gt;=15 AND ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59 GROUP BY ` stage ` 


The result sets

 [{" count ": 1," stage ": 15}, {" count" : 1, "stage" : 16}, {" count ": 1," stage ": 17}, {" stage" "count" : 1:18}] 


In addition a table SQL
 SELECT count (*) as the count, stage FROM ` gametext_other ` WHERE ` status `=0 AND ` isEgg `=0 AND ` stage ` & gt;=15 AND ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59 GROUP BY ` stage ` 


The result sets

 [{" count ": 1," stage ": 15}, {" count" : 1, "stage" : 16}, {" count ": 1," stage ": 17}, {" count" : 1, "stage" : 18}] 


How to use a SQL query of the two tables with the addition of stage, the results for gametext + gametext_other, such as:
 [{" count ": 2, the" stage ": 15}, {" count" : 2, the "stage" : 16}, {" count ": 2, the" stage ": 17}, {" count" : 2, the "stage" : 18}] 

CodePudding user response:

The original data at a less amount of data:
 select count (*) as the count, c.s. tage from 
(select * from gametext
UNION ALL
Select * from gametext_other) as c
WHERE c. ` status `=0 AND c. ` isEgg `=0 AND c. ` stage ` & gt;
=15AND c. ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59'
Group by c.s. tage.


The original data of large amount of data:
 
Select count (*) as the count, c.s. tage from
(SELECT * FROM ` gametext `
WHERE ` status `=0 AND ` isEgg `=0 AND ` stage ` & gt;
=15AND ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59'
UNION ALL
SELECT * FROM ` gametext_other `
WHERE ` status `=0 AND ` isEgg `=0 AND ` stage ` & gt;
=15AND ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59) as c
Group by c.s. tage

CodePudding user response:

reference 1/f, cloud fly me reply:
when the original data is:
 select count (*) as the count, c.s. tage from 
(select * from gametext
UNION ALL
Select * from gametext_other) as c
WHERE c. ` status `=0 AND c. ` isEgg `=0 AND c. ` stage ` & gt;
=15AND c. ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59'
Group by c.s. tage.


The original data of large amount of data:
 
Select count (*) as the count, c.s. tage from
(SELECT * FROM ` gametext `
WHERE ` status `=0 AND ` isEgg `=0 AND ` stage ` & gt;
=15AND ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59'
UNION ALL
SELECT * FROM ` gametext_other `
WHERE ` status `=0 AND ` isEgg `=0 AND ` stage ` & gt;
=15AND ` create_time ` BETWEEN '2020-06-09 00:00:00' AND 'the 2020-06-09 23:59:59) as c
Group by c.s. tage


Thank you, teacher can not post don't know why, some abnormal junction post tips let me contact customer service