can anyone help me on how should i count the jq.batchid != 0 and tl.taskqueueid IS NOT NULL
Here is the initial data:
+---------------+-----------+---------+---------------+
| taskqueueid | batchid | jobid | taskqueueid |
+---------------+-----------+---------+---------------+
| 19 | 0 | 140 | (NULL) |
+---------------+-----------+---------+---------------+
| 21 | 103 | 140 | 21 |
+---------------+-----------+---------+---------------+
| 22 | 104 | 140 | 22 |
+---------------+-----------+---------+---------------+
| 23 | 105 | 140 | (NULL) |
+---------------+-----------+---------+---------------+
| 20 | 0 | 140 | (NULL) |
+---------------+-----------+---------+---------------+
Here is my query:
SELECT COUNT(jq.batchid),COUNT(tl.taskqueueid)
FROM jobqueue jq
LEFT JOIN taskslogs tl
ON jq.taskqueueid=tl.taskqueueid
AND jq.documentgroupid=0
AND jq.batchid!=0
AND tl.statusDefinitionID=1
WHERE jq.jobid=140;
The above query result is:
+--------------------+-----------------------+
| COUNT(jq.batchid) | COUNT(tl.taskqueueid) |
+--------------------+-----------------------+
| 5 | 2 |
+--------------------+-----------------------+
And I want a result of:
+--------------------+-----------------------+
| COUNT(jq.batchid) | COUNT(tl.taskqueueid) |
+--------------------+-----------------------+
| 3 | 2 |
+--------------------+-----------------------+
Can anyone help me on how should I do this.
There’s a very nice trick for these kind of count:
SUM(BOOLEAN CONDITION) gives you exactly the number of rows matching the condition.