我这里有一个语法错误,但找不到它。对这个有什么想法吗?
WITH table_selection AS (SELECT device_name FROM devices WHERE device_id = 8),
column_names AS (SELECT column_name FROM device_parameters WHERE device_id = 8)
SELECT * FROM table_selection
其想法是,table_selection 查询获取表的名称,column_names 查询获取要从该表中读取的列,而 SELECT 将获取 table_selection 中的 column_names 列上的所有值。
完整的错误消息是:
Exception: Error running query:
SQLQuery(query=; WITH table_selection AS (SELECT device_name FROM devices WHERE device_id = 5),
column_names AS (SELECT column_name FROM device_parameters WHERE device_id = 5)
SELECT * FROM table_selection
, database=Logging)@0ms
On: Data Tracker.Root Container.Table 2.data
caused by GatewayException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; WITH table_selection AS (SELECT device_name FROM devices WHERE device_id = 5),' at line 1
caused by MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; WITH table_selection AS (SELECT device_name FROM devices WHERE device_id = 5),' at line 1
Ignition v7.9.5 (b2017111615)
Java: Oracle Corporation 1.8.0_231
最佳答案
为什么不尝试使用JOIN
SELECT device_name,column_names
FROM devices D JOIN device_parameters DP ON D.device_id = DP.device_id
WHERE device_id = 8;
关于mysql - SQL 'with' 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59349125/