0

我在一张表中有 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 个查询合并为一个查询?

4

2 回答 2

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

在http://www.w3schools.com/sql/sql_union.asp了解有关 UNION 的更多信息

于 2013-05-13T10:57:21.483 回答
0

在两者之间使用“联合” - 而不是 and

于 2013-05-13T10:56:24.343 回答