Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having trouble writing queries for SQL NOTE: In the following questions, by

ID: 3921214 • Letter: I

Question

I'm having trouble writing queries for SQL

NOTE: In the following questions, by "local", I mean in the zip codes that begin with 93933, 93901, 93905, 93955, or 93906.

3. Who are the top 10 local contributors in terms of total amount
-- contributed? Show the contributor names and the amount they spent.

The schema looks like

CREATE TABLE candidate
(
cand_id   varchar(12) primary key,
name   varchar(12)
);

(
contbr_id   integer primary key,
name       varchar(20),
city     varchar(40),
street   varchar(40),
zip       varchar(20),
employer   varchar(60),
occupation   varchar(40)
);

CREATE TABLE contribution
(
contb_id   integer primary key,
cand_id   varchar(12),
contbr_id   varchar(12),
amount   numeric(6,2),
date       varchar(20),
election_type varchar(20),
tran_id   varchar(20)
);

Explanation / Answer

SELECT ca.name,c.amount FROM contribution c INNER JOIN candidate ca ON ca.cand_id=c.cand_id WHERE ca.zip LIKE 93%%% ORDER BY c.amount DESC LIMIT 10);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote