sql - 无法在 Postgres 中执行联合
问题描述
对于某些表t
,我想做以下查询:
select 'X' as "Indicator" from t limit 1
union
select 'Y' as "Indicator" from t limit 1
我的期望:
Indicator
X
Y
我得到什么:ERROR: syntax error at or near "union"
为什么会这样?列名相同,在这两种情况下只有一列。怎么了?
解决方案
如果你想要两个结果,就像这样
(select 'X' as "Indicator" from t limit 1)
union
(select 'Y' as "Indicator" from t limit 1)
推荐阅读
- terraform-provider-aws - 如何使用 terraform 中的外部脚本文件引导 ec2 实例?
- html - 如何让我的复选框在选中时返回 True 值?
- python - Python 等效于 MATLAB 函数“ischange”
- python-3.x - 如何在 Synology DSM 上将 Python3 升级到最新版本?
- javascript - 使用WEBRTC截屏,了解用户流选择
- javascript - 正则表达式:如何在javascript中将“ab”拆分为“a”“.b”
- json - Excel COM 加载项中的 JsonServiceClient C#
- java - 如何显示 firebase 数据库中的所有标记?
- html - 继承模板上的 Jinja 范围
- javascript - 如何使用 setState 函数?