请找出下面POSTGRESQL 语句报错的原因with tmpVaa1BaseData as (SELECT DISTINCT t .* FROM ( SELECT A .vaa01 患者编号, A .vaa03 门诊号, A .vaa05 姓名, C .abw02 性别, A .vaa10 || d.aau02 AS 年龄, A .bcq04 床号, a.bdp02 患者类别 FROM vaa1 A JOIN vac1 b ON A .vaa01 = b.vaa01 LEFT JOIN abw1 C ON A .abw01 = C .abw01 LEFT JOIN aau1 d ON A .aau01 = d.aau01 UNION ALL SELECT A .vaa01 患者编号, COALESCE (b.vae94, a.vaa04) AS 住院号, A .vaa05 姓名, C .abw02 性别, A .vaa10 || d.aau02 AS 年龄, A .bcq04 床号, a.bdp02 患者类别 FROM vaa1 A JOIN vae1 b ON A .vaa01 = b.vaa01 LEFT JOIN abw1 C ON A .abw01 = C .abw01 LEFT JOIN aau1 d ON A .aau01 = d.aau01 ) AS t) SELECT DISTINCT t.* FROM (SELECT b.lte09, b .vaa02, A .vaa05, A .abw02, A .bcq04, A .vaa10, b .lte04, c .abl02, d .abn02, e .bck03, b .lte06, (select t.lte09 as lastTransTime from lte1 t where t.vaa01 = a.vaa01 ORDER BY t.lte09 DESC LIMIT 1) lastTransTime, b.lte07, b.bak05, b.lte48, b.lte40, b.lte47, b.lte49, b.lte50, g.bby05, f.lth05, f.lth08, h.ltl02, h.ltl03, h.ltl04, h.ltl05, h.ltl06, h.ltl07, h.ltl08, h.ltl09, h.ltl10, h.ltl11, h.ltl12, h.ltl13, h.ltl14, h.ltl15, h.ltl16, h.ltl17, h.ltl18, h.bce01a, h.ltl19 FROM tmpVaa1BaseData A JOIN lte1 b ON A .vaa01 = b.vaa01 JOIN ltl1 h ON h.lte01 = b.lte01 JOIN bck1 e ON b.bck01a = e.bck01 JOIN lth1 f ON b.lte01 = f.lte01 JOIN bby1 g ON f.bby01 = g.bby01 LEFT JOIN abl1 c ON b.abl02a = c.abl01 LEFT JOIN abn1 d ON b.abn02a = d.abn01
时间: 2024-04-08 16:30:13 浏览: 151
PostgreSQL SELECT 语句
根据提供的SQL语句,我注意到以下问题:
1. 查询语句的最后一行缺少结束括号,导致语法错误。您需要在最后一行的末尾添加一个闭括号。
正确的查询语句应该是这样的:
```sql
LEFT JOIN abn1 d ON b.abn02a = d.abn01
) AS t
SELECT DISTINCT t.* FROM
...
```
请注意,这只是修复了语法错误,但是无法判断查询的完整性和逻辑是否正确。如果您仍然遇到问题,请提供更多的信息和上下文,以便我们更好地帮助您解决问题。
阅读全文