簡體   English   中英

通過id postgres偏移多行

[英]offset multiple rows by id postgres

我正在嘗試從查詢結果中更新多行,但我不能這樣做。

這是我的表結果

15347   108
15665   108
15297   108
15454   105
15850   105
15304   205
15690   205
15360   205

我想僅通過id_num來抵消第一個結果,如15347,15454和15304 ......

這是我正在使用的SQL查詢

select id, id_num from animal where club = 78 offset 1 limit all;

但它只能抵消第一行......這就是我想要的結果

15665   108
15297   108
15454   105
15304   205
15690   205

你是說你想要每個col2的最小col1值? 如果是這樣,這與offset無關。

您的查詢將是這樣的:

select a.*
from animal a
where a.club = 78 and
      a.col1 = (select min(a2.col1)
                from animal a2
                where a2.col1 = a.col1 and a2.club = a.club
               );

您可以使用DISTINCT ON ()

SELECT DISTINCT ON (col2) *
FROM animal
WHERE a.club = 78
ORDER BY id; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM