As shown, to query a user (from the beginning of the registration) 7 days, 15 days, 30 days of the number of posts, the results of the query data serial. Because, there are registered users, he did not post 7 days ago, that is, the number of posts 0, in the data table should be shown as NULL, so the data table in 15 days more data, is the user 7 days post number 0. 30 days of the same reason.
How to solve it? First, the maximum period of 30 days of the main reference table , 30 days including 15 days, 7 days, if he is the reference to the main table, the filtered user ID will certainly have 15 days, 7 days, if not posted, the query display is null.
Statement to write like this.
SELECT * FROM (the virtual table generated by the table query 30 days) the left join (the virtual table generated by the query for 7 days) on the connection conditions of the two virtual tables
SELECT * FROM (the virtual table generated by the table query 30 days) the left join (the virtual table generated by the table query 15 days) on the two virtual table join conditions
SELECT
a.ID, a.user_id, a. ' Registration time ', a. ' Number of posts ', B. ' Number of posts '
From
(
SELECT
Qp.id,
qp.user_id,
Qs.wechat,
from_unixtime (qp.create_at, '%y-%m-%d ') registration time,
count (qp.user_id) Number of posts,
count (qs.id) second-hand quantity,
Qs.create_at,
Uw.create_at as Uwcreate
from
Welife_quan.quan_post as QP
Left JOIN Quan_post_second as qs on qs.pid = Qp.id
Left JOIN welife_system.user_wechat as uw on uw.unionid = qp.user_id
GROUP by
qp.user_id
having
qs.wechat! = "
and qs.create_at <= uwcreate + * + *
ORDER by
qp.id DESC
) as A
Left JOIN (
SELECT
Qp.id,
qp.user_id,
Qs.wechat,
from_unixtime (qp.create_at, '%y-%m-%d ') registration time,
count (qp.user_id) Number of posts,
count (qs.id) second-hand quantity,
Qs.create_at,
Uw.create_at as Uwcreate
from
Welife_quan.quan_post as QP
Left JOIN Quan_post_second as qs on qs.pid = Qp.id
Left JOIN welife_system.user_wechat as uw on uw.unionid = qp.user_id
GROUP by
qp.user_id
having
qs.wechat! = "
and qs.create_at <= uwcreate + * 7 *
ORDER by
qp.id DESC
) as B on a.user_id = b.user_id;
MySQL multi-table query data appears serial