postgresql make output column upper while applying DISTINCT ON

huangapple go评论67阅读模式
英文:

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&#39;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&#39;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 ##
&lt;pre&gt;
approver_wwid | approver_name
ab123         | Jhon Mark
AB123         | Jhon Mark
ab123         | Mark Jhon
CD123         | Dev Tim
cd123         | Dev Tim
&lt;/pre&gt;

## Expected Output ##
&lt;pre&gt;
approver_wwid | approver_name
AB123         | Jhon Mark
CD123         | Dev Tim
&lt;/pre&gt;


</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.

huangapple
  • 本文由 发表于 2020年1月3日 17:47:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576291.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定