Given a database of the results of an election, find the number of seats won by each party. There are some rules to going
Given a database of the results of an election, find the number of seats won by each party. There are some rules to going about this: There are many constituencies in a state and many candidates who are contesting the election from each constituency. Each candidate belongs to a party. The candidate with the maximum number of votes in a given constituency wins for that constituency. The output should be in the following format: Party Seats_won The ordering should be in the order of seats won in descending order. Schema There are 2 tables: Candidates and Results. Candidates Name Description id INTEGER It is the primary key. gender STRING The gender of the candidate. age INTEGER Age of the candidate. party STRING The party to which the candidate belongs to. Results Name Description constituency_id INTEGER It is the constituency to which the candidate is contesting from. candidate_id INTEGER It is the primary key. votes INTEGER The number of votes won by the candidate. v Sample Data Tables Candidates id gender age party 1 M 55 Democratic M 51 Democratic 3 F 62 Democratic M 60 Republic F 61 Republic F 58 Republic Results constituency_id candidate_id votes 1 1 847529 1 4 283409 2 293841 5 394385 3 3 429084 3 6 303890 Expected Output: Democratic 2 Republic 1 2. 2. 2. 4.
Step by Step Solution
3.39 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1 Unlock smart solutions to boost your understanding
Heres the combined SQL code and the resulting data for both queries Query 1 Seats Won by Each ...83% of Sciences Students Improved their GPA!
Step: 2Unlock detailed examples and clear explanations to master concepts
Step: 3Unlock to practice, ask, and learn with real-world examples
See step-by-step solutions with expert insights and AI powered tools for academic success
- Access 30 Million+ textbook solutions.
- Ask unlimited questions from AI Tutors.
- 24/7 Expert guidance tailored to your subject.
- Order free textbooks.
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started