我正在OpenHAB中使用MySQLpersistence。它将创建一个名为Items的表,该表具有两列:ItemID(Int),ItemName(VarChar)。 它为每个项目创建一个表。例如,Item1有两列(时间,值)。 它将对“项目”表中的每个项目编号执行此操作。
我希望能够基于对Item表的查询来选择Item表。
除非这行不通-它只是给我列出了Item#名称...
mysql> select * from (select CONCAT("Item",y.ItemID) as TName from Items y where ItemName like 'F%F') x;
+--------+
| TName |
+--------+
| Item3 |
| Item5 |
| Item26 |
| Item28 |
| Item29 |
| Item30 |
| Item31 |
| Item32 |
| Item33 |
+--------+
9 rows in set (0.06 sec)
--------------------------------------
mysql> describe Items;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| ItemId | int(11) | NO | PRI | NULL | auto_increment |
| ItemName | varchar(200) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> select * from Items limit 3;
+--------+-----------------+
| ItemId | ItemName |
+--------+-----------------+
| 1 | OS_ChickenDoor |
| 2 | FF_Kitchen_Wall |
| 3 | F2_LabF |
+--------+-----------------+
3 rows in set (0.00 sec)
mysql> Describe Item1;
+-------+----------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------------+------+-----+---------------------+-------+
| Time | datetime | NO | PRI | 0000-00-00 00:00:00 | |
| Value | varchar(20000) | YES | | NULL | |
+-------+----------------+------+-----+---------------------+-------+
2 rows in set (0.00 sec)