英文:
postgresql make output column upper while applying DISTINCT ON
问题
我试图在一个列上找到不同的值,并且我想将输出转换为大写
select
DISTINCT ON (UPPER(approver_wwid)) approver_wwid ,
approver_name
from cons_temp
我使用DISTINCT ON是因为名称是模糊的,而wwid可以是不同的。
我只想输出approver_wwid的大写值。
## 示例数据 ##
<pre>
approver_wwid | approver_name
ab123 | Jhon Mark
AB123 | Jhon Mark
ab123 | Mark Jhon
CD123 | Dev Tim
cd123 | Dev Tim
</pre>
## 预期输出 ##
<pre>
approver_
<details>
<summary>英文:</summary>
I'm trying to find distinct on one column and I want to make output to Upper
select
DISTINCT ON (UPPER(approver_wwid)) approver_wwid ,
approver_name
from cons_temp
I'm using Distinct on because name is ambiguous while wwid can be distinct.
I just want to output value of approver_wwid in upper.
## Sample Data ##
<pre>
approver_wwid | approver_name
ab123 | Jhon Mark
AB123 | Jhon Mark
ab123 | Mark Jhon
CD123 | Dev Tim
cd123 | Dev Tim
</pre>
## Expected Output ##
<pre>
approver_wwid | approver_name
AB123 | Jhon Mark
CD123 | Dev Tim
</pre>
</details>
# 答案1
**得分**: 0
这将使您的第一列变成大写:
```sql
SELECT
DISTINCT ON (approver_wwid) UPPER(approver_wwid) AS approver_wwid,
approver_name
FROM cons_temp
但请注意,返回的行不在您的控制之下。在您的情况下,第二列可能是 'Mark Jhon' 或 'Jhon Mark'。
英文:
This will make your first column upper:
SELECT
DISTINCT ON (approver_wwid) UPPER(approver_wwid) AS approver_wwid,
approver_name
FROM cons_temp
But note, that it is not under your control which row will be returned.
In your case it could be 'Mark Jhon' or 'Jhon Mark' for the second column.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论