syntax error at or near “union“

编程入门 行业动态 更新时间:2024-10-12 03:24:36

<a href=https://www.elefans.com/category/jswz/34/1766625.html style=syntax error at or near “union“"/>

syntax error at or near “union“

postgreSQL 使用union时遇到了一个问题:

syntax error at or near "union"

1. 问题 sql 如下:

	select tech_model as model from dim_product_attribute_acc where tech_model is not null group by tech_model order by tech_modelunionselect 'N/A' as model

2. 原因

order by 的问题
order by 不能 和 union 同时使用
正解如下:

with tem as(select tech_model as model from dim_product_attribute_acc where tech_model is not null group by tech_model  order by tech_model
)
select model from tem 
union
select 'N/A' as model

把order 放到外层即可。

更多推荐

syntax error at or near “union“

本文发布于:2024-03-23 16:58:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1740602.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:syntax   error   union

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!