我有一个复杂的mysql查询语言,包括几个子查询,我的最终结果如下。我正在处理它,我无法解决它,这是一种呈现结果的方式。我想知道如何更改结果的结构,结果只在一行中显示,我不想看到NULL字段。我的意思是下面的东西
这是mysql查询
select count(*) as userRetentionSameDay, null as 'userRetentionDiffDay' from (SELECT date(`timestamp`), `user_xmpp_login`
FROM table1
WHERE DATE(`timestamp` ) = CURDATE() - INTERVAL 1 DAY) as res1
right join (select date(ts), user
from table2
WHERE DATE(ts ) = CURDATE() - INTERVAL 1 DAY
and product_id REGEXP ("^(europe+$" )) as lej1
on lej1.user = res1.`user_xmpp_login`
where res1.`user_xmpp_login` IS not NULL
union all
select null as 'userRetentionSameDay', count(*) as userRetentionDiffDay from (SELECT date(`timestamp`), `user_xmpp_login`
FROM table1
WHERE DATE(`timestamp` ) = CURDATE() - INTERVAL 1 DAY) as res1
right join (select date(ts), user
from table2
WHERE DATE(ts ) = CURDATE() - INTERVAL 1 DAY
and product_id REGEXP ("^(europe+$" )) as lej2
on lej2.user = res1.`user_xmpp_login`
where res1.`user_xmpp_login` IS NULL;
这样做的推荐解决方案是什么?
答案 0 :(得分:0)
试试这个。
SELECT A.userRetentionSameDay,B.userRetentionDiffDay FROM(
SELECT COUNT()AS userRetentionSameDay FROM
(
选择日期(timestamp
),user_xmpp_login
FROM table1
WHATE DATE(timestamp
)= CURDATE() - INTERVAL 1 DAY)AS res1
RIGHT JOIN(选择日期(ts),USER
从table2
在哪里日期(ts)= CURDATE() - 间隔1天
AND product_id REGEXP(“^(europe + $”))AS lej1
ON lej1.user = res1。user_xmpp_login
resERE。user_xmpp_login
不是NULL
) 一个,
(
SELECT COUNT()AS userRetentionDiffDay FROM(
选择日期(timestamp
),user_xmpp_login
FROM table1
WHATE DATE(timestamp
)= CURDATE() - INTERVAL 1 DAY
)AS res1
RIGHT JOIN(SELECT DATE(ts),USER 从table2 在哪里日期(ts)= CURDATE() - 间隔1天 AND product_id REGEXP(“^(欧洲+ $”)
)AS lej2
ON lej2.user = res1。user_xmpp_login
resERE。user_xmpp_login
IS NULL
)B; </ p>