我在一个表中有2个查询t_push_member
SELECT
DATE_FORMAT(`member_subscribe_at`, '%d-%m-%y') Tanggal,
count(`member_msisdn`) 'total_reg'
FROM
`t_push_member`
WHERE
`service_keycode`='nocan'
GROUP BY
Tanggal,
'total_reg'
ORDER BY
Tanggal
和
SELECT
DATE_FORMAT(`member_unsubscribe_at`, '%d-%m-%Y') Tanggal,
COUNT(`member_msisdn`) 'total_unreg'
FROM
`t_push_member`
WHERE
`service_keycode`='nocan'
GROUP BY
Tanggal, 'total_unreg'
ORDER BY
Tanggal
如何在一个查询中进行2次查询?
答案 0 :(得分:1)
select *
from
( SELECT DATE_FORMAT(member_subscribe_at, '%d-%m-%y') Tanggal, count(member_msisdn),'REG' as Registered FROM t_push_member
where service_keycode='nocan'
group by Tanggal
UNION
SELECT DATE_FORMAT(member_unsubscribe_at, '%d-%m-%Y') Tanggal, count(member_msisdn),'NOT_REG' as Registered FROM t_push_member
where service_keycode='nocan'
group by Tanggal
)
order by Tanggal
了解有关UNION的更多信息
答案 1 :(得分:0)
在两者之间使用“联合” - 而不是和