From: | Rama Krishnan <raghuldrag(at)gmail(dot)com> |
---|---|
To: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | How to select unique records in PostgreSQL |
Date: | 2022-11-24 12:01:13 |
Message-ID: | CAJWX+ENP=04KZ-bHrNpwkqZL0iFuMkDdXnKK4cs0kZNJVnpM4w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi All,
I want to get the unique wallet_id from this table even it was repeated on
multiple occasions I should calculate only once as well as if the wallet_id
was calculated on previous month it shouldn't be calculate on next months
create table student_id
(
student_wallet_id int,
card_id int,
created_date date
)
insert into student_id values ('w1', 'c1', '2022-04-01')
insert into student_id values ('w1', 'c2', '2022-04-03')
insert into student_id values ('w1', 'c3', '2022-04-04')
insert into student_id values ('w1', 'c4', '2022-05-01')
insert into student_id values ('w2', 'c1', '2022-05-01')
insert into student_id values ('w2', 'c2', '2022-05-04')
insert into student_id values ('w3', 'c4', '2022-05-05')
insert into student_id values ('w3', 'c6', '2022-06-03)
insert into student_id values ('w3', 'c7', '2022-06-05')
insert into student_id values ('w3', 'c8', '2022-06-07')
expected output:
-------------------
months count_wallet_id
2022-04 1
2022-05 2
2022-05 0
Regards
A.Rama Krishnan
From | Date | Subject | |
---|---|---|---|
Next Message | Anna B. | 2022-11-24 14:45:03 | Index-only scan not working when IN clause has 2 or more values |
Previous Message | Ryo Yamaji (Fujitsu) | 2022-11-24 10:06:54 | About row locking ordering |