I'm trying to grab all the info I want through the following query. That is comment value where status = 0 and SUM points where status = 0 and where status = 1. Here is what I've got until now (I can't grab the comment value at this point)
SELECT
IF(status = 0, comment, NULL) AS com,
SUM(IF(status = 0, points, 0)) AS points1,
SUM(IF(status = 1, points, 0)) AS points2
FROM `tablename`
WHERE mid = $mid
AND stage = 0
Table data:
+----+--------+--------+-----------+-----+------+
| id | mid | points | comment |stage|status|
+----+--------+--------+-----------+-----+------+
| 1 | 500 | 15 | Text here | 0 | 0 |
| 2 | 500 | 5 | Blablabla | 0 | 1 |
| 3 | 20 | 7 | | 1 | 0 |
| 4 | 356 | 10 | More text | 0 | 2 |
| 5 | 9 | 0 | | 1 | 0 |
| 6 | 52 | 5 | Text etc | 0 | 1 |
| 7 | 520 | 13 | Texting | 1 | 0 |
| 8 | 540 | 8 | | 0 | 0 |
+----------------------------------------+------+
Results I am looking for:
- Where
mid = 500andstage = 0 - IF
status = 0get me the points (15in this case) - IF
status = 1get me the points (5in this case) - IF
status = 0get me the comment (Text herein this case)