Maliq
Maliq

Reputation: 1

mysql multiple count in single table

i have 2 query in one table 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

and

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

how to make 2 queries into one query ?

Upvotes: 0

Views: 134

Answers (2)

Ankur Trapasiya
Ankur Trapasiya

Reputation: 2200

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

Learn more about UNION at http://www.w3schools.com/sql/sql_union.asp

Upvotes: 1

exussum
exussum

Reputation: 18550

use "union" between the two - Instead of and

Upvotes: 0

Related Questions