There are two requests

`SELECT order_customFields.order_customFields_delivery_method method, sum(case `order`.order_status when 'paid' then 1 else 0 end) paid, sum(case `order`.order_status when 'later' then 1 else 0 end) later FROM order_customFields INNER JOIN `order` ON order_customFields.order_id = `order`.order_id WHERE order_customFields.order_customFields_order_date >= date_sub(date_sub(curdate(), interval day(curdate()) - 1 day), interval 1 month) and order_customFields.order_customFields_order_date < date_sub(curdate(), interval day(curdate()) - 1 day) AND order_customFields.order_customFields_delivery_method is not null GROUP BY order_customFields.order_customFields_delivery_method ` 

Second request

 `SELECT total,from_sale,from_sent,on_sent FROM deliverability.delivery_count_repo where add_time >= CURDATE()` 

The result of the first is the output of 3 columns, the result of the second is the conclusion of 5 columns. How can I combine them into one, so that the output has 8 columns?

  • the result of the second conclusion is 5 columns. I counted only 4 ... How can you combine them into one, so that the output has 8 columns? No way, until the sane criterion for matching the records of the first and second sets appears, and strictly 1: 1. - Akina

1 answer 1

Combine, of course, possible. Only without a relationship between the tables you get a hodgepodge.
And also the number of records will be Count(table1) * Count(table2) .

You just need to make a SELECT * FROM table1, table2 type construct.

Something like this:

 SELECT t1.*, t2.* FROM (SELECT order_customFields.order_customFields_delivery_method method, sum(case `order`.order_status when 'paid' then 1 else 0 end) paid, sum(case `order`.order_status when 'later' then 1 else 0 end) later FROM order_customFields INNER JOIN `order` ON order_customFields.order_id = `order`.order_id WHERE order_customFields.order_customFields_order_date >= date_sub(date_sub(curdate(), interval day(curdate()) - 1 day), interval 1 month) and order_customFields.order_customFields_order_date < date_sub(curdate(), interval day(curdate()) - 1 day) AND order_customFields.order_customFields_delivery_method is not null GROUP BY order_customFields.order_customFields_delivery_method) t1, (SELECT total,from_sale,from_sent,on_sent FROM deliverability.delivery_count_repo where add_time >= CURDATE()) t2 

Well, that is, roughly speaking, you enclose each request in a subquery, a comma between them, and "select all".

t1.*, t2.* can be easily replaced simply with *