I have this table :
+--------------+-----------------------------+----------------+
| Username | Message | Status |
+--------------+-----------------------------+----------------+
| jamesbond | I need some help | SendingOK |
| jamesbond | I need some help | SendingOK |
| jamesbond | I need some help | SendingFailed |
| jamesbond | Mission accomplished | SendingOK |
+--------------+-----------------------------+----------------+
produced by this SQL syntax :
SELECT A.Username, A.Message, B.Status
FROM db1.SmsBroadcast as A
INNER JOIN db2.sentitems as B
ON A.MessageSMS1 = B.TextDecoded
WHERE A.Username = 'jamesbond'
GROUP BY Message, Status
now how to have this output?
+--------------+-----------------------------+-----------+---------------+
| Username | Message | SendingOK | SendingFailed |
+--------------+-----------------------------+-----------+---------------+
| jamesbond | I need some help | 2 | 1 |
| jamesbond | Mission accomplished | 1 | 0 |
+--------------+-----------------------------+-----------+---------------+
SendingOK and SendingFailed column is actually can be calculated using COUNT(*), but I have no idea how to count based on same Message, while those message is executed in same SQL syntax. any idea how to do it?
You can simply use
CASEin yourSELECTstatement and GROUPED them byusernameandmessage.