繁体   English   中英

我可以在mysql select查询中使用一个表字段值作为第二个表字段名称吗?

[英]Can I use one table field value as second table field name in mysql select query?

场景:

表1的字段名称命名为testtable

ID,名称,大小,宽度,高度

表2的字段名称命名为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 | <>       |
+----+-------------------------------------+--------+--------+----------+

现在我想从测试表检查:

  1. 计算所有那些尺寸>宽度的记录

  2. 计算大小>高度的所有记录

  3. 计算宽度<>高度的所有那些记录。

所需输出

+-------------------------------------+-------+
|              errorname              | count |
+-------------------------------------+-------+
| size should not greater than width  |     6 |
| size should not greater than height |     2 |
| with should be equal to height      |     3 |
+-------------------------------------+-------+

有可能这样做吗?

当前查询:

从错误表中按ID选择desc,(从testtable中选择count(*)作为“ Total Errors”,其中errortable.field1 errortable.operator errortable.field2)

感谢所有发表评论的人,我在您的评论中得到了我的答案,并通过处理php中的一些代码实现了此方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM