I'm newbie in MYSQL.
I have a table like below:
colmnA colmnB
A x
A y
B x
B z
C x
D null
What I want to achieve is something like:
SELECT
COUNT(distinct colmnA) WHERE colmnB IS NOT NULL AS deployed,
COUNT(distinct colmnA) WHERE colmnB IS NULL AS undeployed
FROM table
which will be resulted in:
deplyed undeployed
3 1
is there an elegant way to achieve this with a single query? thanks for help
As far as I've searched, the most closed solution is combining SUM() with CASE condition, ex:
SELECT SUM(CASE WHEN columnB IS NOT NULL then 1 else 0) AS deployed
but it will include duplicated count, and there is no way to add DISTINCT into SUM().