Knowee
Questions
Features
Study Tools

Write a query that displays the number of players in each state, with FR, SO, JR, and SR players in separate columns and another column for the total number of players. Order results such that states with the most players come first.

Question

Write a query that displays the number of players in each state, with FR, SO, JR, and SR players in separate columns and another column for the total number of players. Order results such that states with the most players come first.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Assuming you are using SQL and you have a table named "players" with columns "state", "year" (FR, SO, JR, SR), the query could look something like this:

SELECT 
    state,
    COUNT(CASE WHEN year = 'FR' THEN 1 END) AS FR,
    COUNT(CASE WHEN year = 'SO' THEN 1 END) AS SO,
    COUNT(CASE WHEN year = 'JR' THEN 1 END) AS JR,
    COUNT(CASE WHEN year = 'SR' THEN 1 END) AS SR,
    COUNT(*) AS total
FROM 
    players
GROUP BY 
    state
ORDER BY 
    total DESC;

Here's a step-by-step explanation of this query:

  1. SELECT state: This selects the "state" column from your table.

  2. COUNT(CASE WHEN year = 'FR' THEN 1 END) AS FR: This counts the number of 'FR' players in each state.

  3. COUNT(CASE WHEN year = 'SO' THEN 1 END) AS SO: This counts the number of 'SO' players in each state.

  4. COUNT(CASE WHEN year = 'JR' THEN 1 END) AS JR: This counts the number of 'JR' players in each state.

  5. COUNT(CASE WHEN year = 'SR' THEN 1 END) AS SR: This counts the number of 'SR' players in each state.

  6. COUNT(*) AS total: This counts the total number of players in each state.

  7. FROM players: This specifies the table from which to select the data.

  8. GROUP BY state: This groups the results by state.

  9. ORDER BY total DESC: This orders the results by the total number of players in descending order, so states with the most players come first.

This problem has been solved

Similar Questions

Sports Craft Company has organized tournaments in multiple individual sports and invited top ranked players to play. Each tournament comprises of multiple matches in knock out format. Each match is played between two players.Problem Statement: Create the Player table as per information provided below:Column Name Data Type Constraint DescriptionPId INTEGER PRIMARY KEY Unique player Id is mandatory for every playerPName VARCHAR2(20) NOT NULL Player NameRanking INTEGER Player's ranking

create a structure name teams in the attribute team names and n scores. sort the scores in ascending order

ou are given two tables: Students and Grades. Students contains three columns ID, Name and Marks.Grades contains the following data:Ketty gives Eve a task to generate a report containing three columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades are entered first. If there is more than one student with the same grade (8-10) assigned to them, order those particular students by their name alphabetically. Finally, if the grade is lower than 8, use "NULL" as their name and list them by their grades in descending order. If there is more than one student with the same grade (1-7) assigned to them, order those particular students by their marks in ascending order.Write a query to help Eve.Sample InputSample OutputMaria 10 99Jane 9 81Julia 9 88 Scarlet 8 78NULL 7 63NULL 7 68

Problem StatementIn a gaming tournament, players are ranked in ascending order based on their scores. Your task is to design a program using binary search to determine the score of the player positioned at the kth place, enabling the organizers to swiftly identify individual performance levels. The program takes the total number of players, their sorted scores, and the rank (k) as input, and outputs the score of the player ranked at the kth position(position value starts from 1).Input format :The first line of input consists of an integer N, representing the total number of players in the tournament.The second line consists of N distinct space-separated integers, representing the sorted list of players' scores.The third line consists of an integer k, representing the rank of the player whose score needs to be determined.Output format :The output prints a single integer, representing the score of the player ranked at position k in the tournament.Code constraints :1 ≤ N ≤ 101 ≤ score ≤ 1001 ≤ k ≤ NSample test cases :Input 1 :712 15 34 47 49 57 583Output 1 :34Input 2 :624 25 37 48 98 995Output 2 :98

Create a procedure named 'displayTeamStrength' which accepts an input parameter. The input parameter is 'teamid' with number as its data type. This procedure should display the number of players in that team, number of players got the skill named 'Batsmen' for the given 'teamid'.If the teamid passed as an argument matches with the id of the team in the team table then display the output in the following format:Team Strength------------------------NUMBER of PLAYERS : 13NUMBER of BATSMEN : 6If the teamid given does not matches with the id in the team table,then it throws an 'no_data_found' exception and display 'No Such Team'.Hints:Procedure name : displayTeamStrengthInput parameter : teamidOutput parameter : NA

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.