SELECT * FROM t1 (select SENSOR_ID, DAM_ID, left(UPLOAD_TIME,10) as UPLOAD_TIME, WATER_TOP, WATER_LEVEL, HOLE_DEPTH, ( HOLE_DEPTH - WATER_LEVEL ) AS BURIED_DEPTH from B_DAM_WATER_LEVEL where ID in( select max([ID]) from B_DAM_WATER_LEVEL where left(UPLOAD_TIME,10) = '2023-05-16' and SENSOR_ID = 1 group by left(UPLOAD_TIME,19))) t1 INNER JOIN setting_single_coordinate ssc ON t1.DAM_ID= ssc.dam_id WHERE ssc.set_type= 0 AND sys_type = 3 这个语句报错 select 附近报错
时间: 2024-03-27 12:39:04 浏览: 69
在Spring中用select last_insert_id()时遇到问题
你提交的 SQL 语句中使用了两个 FROM 子句,这是错误的。正确的写法是将子查询放到一个括号中,并为其指定一个别名,然后在该别名后面使用 INNER JOIN 子句。请尝试使用以下 SQL 语句:
```
SELECT *
FROM
(
SELECT SENSOR_ID, DAM_ID, LEFT(UPLOAD_TIME, 10) AS UPLOAD_TIME, WATER_TOP, WATER_LEVEL, HOLE_DEPTH, (HOLE_DEPTH - WATER_LEVEL) AS BURIED_DEPTH
FROM B_DAM_WATER_LEVEL
WHERE ID IN (
SELECT MAX(ID)
FROM B_DAM_WATER_LEVEL
WHERE LEFT(UPLOAD_TIME, 10) = '2023-05-16'
AND SENSOR_ID = 1
GROUP BY LEFT(UPLOAD_TIME, 19)
)
) AS t1
INNER JOIN setting_single_coordinate ssc ON t1.DAM_ID = ssc.dam_id
WHERE ssc.set_type = 0
AND sys_type = 3;
```
阅读全文