Im having trouble writing queries for SQL NOTE In the follow
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)
);
Solution
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);