想象一下這張桌子:
col_A col_B
banana 1
apple 1
banana 45
banana 1
kiwi 2
grape 2
grape 33
strawberry 56
strawberry 56
我想回傳:
col_A col_B
banana 1
banana 45
grape 2
grape 33
我想不出獲得這個結果的方法或函式。希望得到建議。
uj5u.com熱心網友回復:
這應該在 postgre sql 中作業
模式定義
CREATE TABLE test_dp (
"firsttt" VARCHAR(10),
"secondd" INTEGER
);
INSERT INTO test_dp
("firsttt", "secondd")
VALUES
('banana', '1'),
('apple', '1'),
('banana', '45'),
('banana', '1'),
('kiwi', '2'),
('grape', '2'),
('grape', '33'),
('strawberry', '56'),
('strawberry', '56');
詢問
select
distinct(dp1.*)
from
test_dp dp1
inner join test_dp dp2 on dp1.firsttt = dp2.firsttt
and dp1.secondd <> dp2.secondd;
DB Fiddle 英國
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/446058.html
標籤:sql 数组 PostgreSQL
