Рет қаралды 983
#sql #education #sqlfunctions #dataanalyst #dataengineers
#MeanLifeStudies #sqlinterview #datascience #interview #dataanalystinterview
Here are My profiles that will definitely help your preparation for data analyst or data engineer roles.
Medium: / mahendraee204
Github: github.com/mah...
Q) Given the election and candidate's details. Find Who won the election.
Assuming the election is conducted in a city where everyone can vote for one or more candidates or choose not to vote.
Each person has 1 vote so if they vote for multiple candidates, their vote gets equally split across candidates.
Here are table creation and insertion statements:
------------------------------------------------------------------------
create table Election (
voter_id int,
candidate_id int
);
insert into Election values (1, 2),(2, 3),(2, 1),(2, 2),(3, null),(4, 3),(4, 2),
(4, 1),(5, 3),(6, 2),(6, 1),(7, 3),(7, 2),(7, 1),(8, null),(9, 2),(9, 1),(10, 2),(10,3);
create table candidates (id int, name varchar(10))
insert into candidates values(1,'Rah'),(2,'ketan'),(3,'mahi')