Scenario:
Field names of Table1 named as testtable
id,name,size,width,height
Field names of Table2 named as errortable
id,desc,field1,field2,operator
Values of errortable
+----+-------------------------------------+--------+--------+----------+
| id | desc | field1 | field2 | operator |
+----+-------------------------------------+--------+--------+----------+
| 1 | size should not greater than width | size | width | > |
| 2 | size should not greater than height | size | height | > |
| 3 | with should be equal to height | width | height | <> |
+----+-------------------------------------+--------+--------+----------+
Now I want to check from testtable
:
- count all those records where size > width.
- count all those records where size > height.
- count all those records where width <> height.
Required Output
+-------------------------------------+-------+
| errorname | count |
+-------------------------------------+-------+
| size should not greater than width | 6 |
| size should not greater than height | 2 |
| with should be equal to height | 3 |
+-------------------------------------+-------+
Is it possible to do like this?
Current query:
select desc,
(select count(*) as "Total Errors"
from testtable
where errortable.field1 errortable.operator errortable.field2 )
from errortable group by id;