本文介绍了从一列中不同的行中选择所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netezza(基于PostgreSQL),并且需要为一个列中不同的行选择表中的所有列.可以在此处找到与答案相关的问题,但是没有. t处理所有列的情况,该答案将引发错误:

I am using Netezza (based on PostgreSQL) and need to select all columns in a table for rows distinct on one column. A related question with answer can be found here, but it doesn't handle the case with all columns, going by that answer throws an error:

select distinct on (some_field) table1.* from table1 order by some_field;

包含真实数据的错误摘录:

Snippet from error with real data:

推荐答案

我认为您的代码不应在Postgres中引发错误.但是,如果没有order by,它将无法实现您的期望:

I don't think your code should throw an error in Postgres. However, it won't do what you expect without an order by:

select distinct on (some_field) table1.*
from table1
order by some_field;

这篇关于从一列中不同的行中选择所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 13:03