Re: dumb question
| От | David G. Johnston |
|---|---|
| Тема | Re: dumb question |
| Дата | |
| Msg-id | CAKFQuwaDXFvGoycgH5BfcHuwjy3Q92DFdU_iBsCOrFdbvJS55Q@mail.gmail.com обсуждение исходный текст |
| Ответ на | dumb question (Steve Clark <steve.clark@netwolves.com>) |
| Список | pgsql-general |
On Thursday, June 2, 2016, Steve Clark <steve.clark@netwolves.com> wrote:
Hi List,
I am a noob trying to do something that seems like it should be easy but I can't figure it out.
I have a table like so:
id | ref_id | sts
------------------
1 | | 0
2 | 1 | 1
3 | | 0
4 | | 0
5 | 4 | 1
6 | | 0
7 | 6 | 1
I want to find the max(id) whose sts is 0 but whose id is not referenced by ref_id.
so the answer would be id=3.
Thanks for any pointers,
Steve
So, of all the rows whose sts is 0 and the id is not in (or not exists) ref_id....subquery for selection
Give me the maximum id...parent query with group by.
David J.
В списке pgsql-general по дате отправления: