question

zhshengj avatar image
zhshengj asked

MYSQL 5.1 Select Statement

How many people did not vote a "straight ticket" (voted for at least two parties)

Select count(*)
From (
Select B.Voter_ID, count(*) AS x
From Voter V,Candidate C,Vote B
Where V.Party != V.Party
And B.Voter_ID = V.Voter_ID
And B.Candidate_ID = C.Candidate_ID
Group By B.Voter_ID Having x>=2
)
As y; 

This comes out to be a empty set.

CREATE TABLE Vote(
Vote_ID int,
Voter_ID int,
Candidate_ID int,
Title varchar(50),
PRIMARY KEY(Vote_ID)
);
CREATE TABLE Voter(
Voter_ID int,
First_Name varchar (50),
Mid_Name varchar(50),
Last_Name varchar(50),
Street varchar(45),
Zipcode int,
Party varchar(20),
Registered int,
PRIMARY KEY(Voter_ID)
);
CREATE TABLE Candidate(
Candidate_ID int,
First_Name varchar(50),
Mid_Name varchar(50),
Last_Name varchar(50),
Street varchar(45),
Zipcode int,
Party varchar(20),
Local_PosID int,
State_PosID int,
National_PosID int,
PRIMARY KEY(Candidate_ID)
);
selectmysqlcount
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.