【发布时间】:2016-02-07 07:42:24
【问题描述】:
场景:
Table1 的字段名称命名为 testtable
id、名称、大小、宽度、高度
Table2的字段名称命名为errortable
id,desc,field1,field2,运算符
错误表的值
+----+-------------------------------------+--------+--------+----------+
| 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 | <> |
+----+-------------------------------------+--------+--------+----------+
现在我想从 testtable 中检查:
计算大小>宽度的所有记录
计算大小>高度的所有记录
计算宽度 高度的所有记录。
所需输出
+-------------------------------------+-------+
| errorname | count |
+-------------------------------------+-------+
| size should not greater than width | 6 |
| size should not greater than height | 2 |
| with should be equal to height | 3 |
+-------------------------------------+-------+
这样可以吗?
当前查询:
select desc,(select count(*) as "Total Errors" from testtable where errortable.field1 errortable.operator errortable.field2 ) from errortable group by id
【问题讨论】:
-
MySQL 还是 Postgeslq?不要标记未涉及的产品...
-
任何人,我都需要
-
之所以称它们为关系数据库,是因为它们都是关于表之间的关系,而这两个表之间没有关系
-
关系是不可能的,我有一个错误列表,我想检查另一个表中是否存在许多错误,就是这样,
-
不,因为您正在尝试使用字段值作为字段名称,而我想不出在 MySQL 中这样做的方法。
标签: php sql database postgresql codeigniter