gpt4 book ai didi

sql - 'union' 处或附近的 PostgreSQL 语法错误

转载 作者:行者123 更新时间:2023-11-29 11:15:13 32 4
gpt4 key购买 nike

我有一个小查询,还有一个联合将另一个小查询放在它旁边。但是,联合中存在语法错误。

Select <column1>
,<column2>
,<column3>
From <Table1>
<Some joins in there>
where <conditions>
order by <column2>

union

select <column2>
,<column3>
,<column4>
from <Table2>
<Some more joins here>
where <conditions>
order by <column2>

这是我收到的错误

ERROR: Syntax error at or near 'union'

最佳答案

我知道出了什么问题。您必须在查询末尾放置订单,并且只能在末尾放置。它给了我一个错误,因为它认为查询已经结束。

Select <column1>
,<column2>
,<aggregate column3>
From <Table1>
<Some joins in there>
Where <conditions>
group by <column2>, <column1>

union

select <column2>
,<column3>
,<aggregate column4>
From <Table2>
<Some more joins here>
Where <conditions>
group by <column2>, <column3>
order by <column2>

成功了。

关于sql - 'union' 处或附近的 PostgreSQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24020078/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com