SQL help? - Mailing list pgsql-novice

From Dr. Drexl Spivey
Subject SQL help?
Date
Msg-id 1558513019.9205.10.camel@little-beak.com
Whole thread Raw
Responses Re: SQL help?  (Saurabh Agrawal <mail@saurabhagrawal.net>)
Re: SQL help?  ("David G. Johnston" <david.g.johnston@gmail.com>)
RE: SQL help?  ("Vianello, Daniel A" <Daniel.Vianello@charter.com>)
List pgsql-novice
Trying to do something very easy, but can't quite figure out the logic.
Typing out the email, and see if I can't figure it out just typing it
out.

Have two tables:

petitions
id = (int)primary key
name = text description

and the following

signed_petitions
signed_id = references petitions.id (Foreign key)
joined = boolean

my goal is to list those petitions that have the most signatures, so I
have to get a count of joined=true, and list the names.

What confuses me on a fundamental level, is the usage of the Foreign
key, reference. But, here is my best attempt.

Ok, this is a lot harder than I thought, because the boolean is not
actually a number. So I guess I will have to use a rank?

SELECT 
    petitions.id
    petitions.name
    RANK() OVER (PARTITION BY signed_petitions.joined) AS total_signed
WHERE 
    signed_petitions.joined = "TRUE"
ORDER BY total_signed DESC
LIMIT 10



I am not sure how the rank() over (partition by... works), this is my
first attempt.

Would this give me the ten highest signed petitions?



pgsql-novice by date:

Previous
From: "Dr. Drexl Spivey"
Date:
Subject: Re: Novice SQL question
Next
From: Saurabh Agrawal
Date:
Subject: Re: SQL help?