postgresql: 提取同类别的第一个排序记录

在数据中心中,我们记录了元数据的多个版本,现在需要提取所有元数据的最新版本,如何用一个sql来表达呢?

CREATE TABLE mdversion
(
  id serial NOT NULL,
  xml text NOT NULL DEFAULT ''::text,
  ts_created timestamp without time zone NOT NULL DEFAULT now(),
  uuid uuid NOT NULL,
  CONSTRAINT mdversion_pkey PRIMARY KEY (id)
)

 

第一感觉,是用group功能,但group不能对同类下的行进行排序,所以解决不了这个问题。

 

用这几个关键词搜索:postgresql group  get first,找到了一个直接相关的解决方案:

Select first row in each GROUP BY group?

解决方案很简单,就是用distinct on方法:

select distinct on (uuid) id from en.mdversion
order by uuid,ts_created desc

 

 


已发布

分类

来自

标签:

评论

《 “postgresql: 提取同类别的第一个排序记录” 》 有 13 条评论

  1. enclomiphene no dr

    online order enclomiphene generic overnight shipping

  2. pilules chinoises kamagra à vendre aux états-unis

    kamagra sans docteur rx

  3. cheapest buy androxal generic pharmacy in canada

    buy androxal generic canada

  4. how to order dutasteride buy for cheap

    get dutasteride cheap genuine

  5. buy cheap flexeril cyclobenzaprine usa online pharmacy

    sex pills flexeril cyclobenzaprine

  6. cheapest buy gabapentin australia pharmacy

    price gabapentin

  7. purchase fildena cheap usa

    cheap fildena generic efficacy

  8. discount itraconazole cheap info

    buy itraconazole cheap next day delivery

  9. cheapest buy staxyn without recipe

    cheap staxyn canadian pharmacy

  10. buying avodart generic tablets

    cheap avodart generic mexico

  11. how to buy xifaxan canada medicine

    order xifaxan usa drugstore

  12. cheapest buy rifaximin ireland over the counter

    canadian meds rifaximin

  13. velitel kamagra generický

    generickテス kanadskテス kamagra co bez lテゥkaナ冱kテゥho pナ册dpisu

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注