Im having trouble writing with my writing a query for SQL In
I\'m having trouble writing with my writing a query for SQL
In the following questions, by \"local\", I mean in the zip codes that begin with 93933, 93901, 93905, 93955, or 93906.
2. For each of the local zip codes, and each of the candidates, show the number of contributions (if at least one contribution was made). Order by zip code and then number of contributions.
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 conut(contbr_id)
FROM candidate
Where cand_id ( Select cand_id
From contribution
group by cand_id
Having conut(contbr_id)> 0
order by conut(contbr_id)
)
Order By zip
