Question

In: Computer Science

List the players that have either won more than 2 matches or lost more than 2...

  1. List the players that have either won more than 2 matches or lost more than 2 matches. List the player number, name, initials, won, and lost. Insert your snip here.
  1. Which players are captains of a team and have ever served as a committee members? Display the player number, player name, initials, team number, and committee member position. This will require 3 tables. Insert your snip here.
  1. Using a subquery, have any other players been penalized the same amount as player 8? Let MySQL do the work for you. Do not explicitly query for $25. Display the player number, player name, initials, and amount. Insert your snip here.
  1. Who has played more than 2 matches? Display the player number as ‘Number’, concatenate the player name (initials, space, name) as ‘Name’, and the number of matches played as ‘Number of Matches’. Insert your snip here.
  1. Sum the number of match wins and losses by player number. Display the player number as ‘Number’, concatenate the player name (initials, space, name) as ‘Name’, wins as ‘Total Wins’, and losses and ‘Total Losses’. Insert your snip here.

***********************************************************************************************************************************************

***********************************************************************************************************************************************

***********************************************************************************************************************************************

Create database tennis;

USE tennis;

#--Create table players and fill it--------------------------

Create table players
(
playerno   int       not null    primary key,
name       varchar(15)   not null,
initials   varchar(3),
birth_date   date,
gender       char(1),
joined       int   not null,
street       varchar(15)   not null,
houseno       varchar(4),
zip       char(6),
town       varchar(10)   not null,
phoneno       char(10),
leagueno   char(4)
);

Insert into players values
(2,'Everett','R','1988-01-09','M',2000,'Stoney Road','43','3575NH','Stratford','070-237893','2411'),
(6,'Paramenter','R','1984-06-25','M',2002,'Haseltine Lane','80','1234KK','Stratford','070-476547','8467'),
(7,'Wise','GWS','1983-05-11','M',2006,'Edgecombe Way','39','9758VB','Stratford','070-347689',Null),
(8,'Newcastle','B','1982-07-08','F',2005,'Station Road','4','6584RO','Inglewood','070-458458','2983'),
(27,'Collins','DD','1990-05-10','F',2008,'Long Drive','804','8457DK','Eltham','079-234857','2513'),
(28,'Collins','C','1983-06-22','F',2008,'Old Main 28','10','1294QK','Midhurst','071-659599',Null),
(39,'Bishop','D','1986-10-29','M',2005,'Eaton Square','78','9629CD','Stratford','070-393435',Null),
(44,'Baker','E','1983-09-01','M',2010,'Lewis Street','23','4444LJ','Inglewood','070-368753','1124'),
(57,'Brown','M','1981-08-17','M',2007,'Edgecombe Way','16','4377CB','Stratford','070-473458','6409'),
(83,'Hope','PK','1976-11-11','M',2009,'Magdalene Road','16A','1812UP','Stratford','070-353548','1608'),
(94,'Miller','P','1993-05-14','M',2013,'High Street','33A','5746OP','Douglas','070-867564',Null),
(100,'Parmenter','P','1983-02-28','M',2012,'Haseltine Lane','80','1234KK','Stratford','070-494593','6524'),
(104,'Moorman','D','1990-05-10','F',2014,'Stout Street','65','9437AO','Eltham','079-987571','7060'),
(112,'Bailey','IP','1983-10-01','F',2014,'Vixen Road','8','6392LK','Plymouth','010-548745','1319');

#--Create the table committee_members and fill it--------------------

Create table committee_members
(
playerno   int   not null,
begin_date   date   not null,
end_date   date,
position   varchar(20),
primary key(playerno, begin_date)
);

Insert into committee_members values
(2,'2010-01-01','2012-12-31','Chairman'),
(2,'2014-01-01',Null,'General Member'),
(6,'2010-01-01','2010-12-31','Secretary'),
(6,'2011-01-01','2012-12-31','General Member'),
(6,'2012-01-01','2013-12-31','Treasurer'),
(6,'2013-01-01',Null,'Chairman'),
(8,'2010-01-01','2010-12-31','Treasurer'),
(8,'2011-01-01','2011-12-31','Secretary'),
(8,'2013-01-01','2013-12-31','General Member'),
(8,'2014-01-01',Null,'General Member'),
(27,'2010-01-01','2010-12-31','General Member'),
(27,'2011-01-01','2011-12-31','Treasurer'),
(27,'2013-01-01','2013-12-31','Treasurer'),
(57,'2012-01-01','2012-12-31','Secretary'),
(94,'2014-01-01',Null,'Treasurer'),
(112,'2012-01-01','2012-12-31','General Member'),
(112,'2014-01-01',Null,'Secretary');

#--Create the table matches and Fill it-------------------

Create table matches
(
matchno       int   not null   Primary Key,
teamno       int   not null   references teams(teamno),
playerno   int   not null   references players(playerno),
won       int,
lost       int
);


Insert into matches values
(1,1,6,3,1),
(2,1,6,2,3),
(3,1,6,3,0),
(4,1,44,3,2),
(5,1,83,0,3),
(6,1,2,1,3),
(7,1,57,3,0),
(8,1,8,0,3),
(9,2,27,3,2),
(10,2,104,3,2),
(11,2,112,2,3),
(12,2,112,1,3),
(13,2,8,0,3);

#--Create Table Penalties and Fill it-------------------------------------

create table Penalties
(
paymentno   int   not null   Primary Key,
playerno   int   not null   references players(playerno),
payment_Date   date   not null,
amount   decimal(10,2)   not null
);


Insert into Penalties values
(1,6,'2010-12-08',100.00),
(2,44,'2011-05-05',75.00),
(3,27,'2013-09-10',100.00),
(4,104,'2014-07-08',50.00),
(5,44,'2010-12-08',25.00),
(6,8,'2010-12-08' ,25.00),
(7,44,'2012-12-30',30.00),
(8,27,'2014-08-12',75.00);

#--Create Table Teams and Fill it----------------------------------------------

Create table teams
(
teamno   int   Primary Key   Not Null,
playerno   int   Not Null   references players(playerno),
division   varchar(6)
);


Insert into teams values
(1,6,'first'),
(2,27,'second');

/* ********************************************************************************************
End of loading the database
******************************************************************************************** */

Solutions

Expert Solution

SQL query is in the order of the question asked

Query1

select p.playerno, p.name, p.initials, m.won, m.lost

from players as p , matches as m

where m.playerno = p.playerno and (m.won >2 or m.lost >3)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Query2

select p.playerno, p.name, p.initials, t.teamno, c.position

from players as p , teams as t, committee_members as c

where t.playerno = p.playerno and c.playerno = p.playerno;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Query3

select p.playerno, p.name, p.initials, pen.amount from players as p,

(select * from Penalties where amount = (select amount from Penalties where playerno=8) and playerno !=8) as pen

where p.playerno in (select playerno from Penalties where amount =

(select amount from Penalties where playerno=8) and playerno !=8)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Query4

select p.playerno as "Number" , CONCAT(p.initials, ' ', p.name) as "Name" , m.sum as "Number of Matches" from players as p ,
(select playerno, sum(won) + sum(lost) as "sum" from matches group by playerno having sum(won)+ sum(lost) >2) as m
where p.playerno = m.playerno;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Query5

select p.playerno as "Number" , CONCAT(p.initials, ' ', p.name) as "Name", m.won as "Total Wins", m.lost as "Total Losses"

from players as p ,

(select playerno, sum(won) as "won", sum(lost) as "lost" from matches group by playerno) as m

where m              .playerno = p.playerno


Related Solutions

1.Which players have lost more matches than the average number of losses?   No duplicates should be...
1.Which players have lost more matches than the average number of losses?   No duplicates should be listed.   Order by player number.   Insert your screen shot here. 2.How many players from each town served on the committee in any capacity? Display the town as ‘Town’ and the number served as ‘Committee Service’.   Insert your screenshot here. 3.How many members come from each town? Display the town as ‘Town’ and the number of members as ‘Number’. Insert your screenshot here. 4.Who has...
Speculate as to why eukaryotes have either a) much more complex promoter and enhancer regions than...
Speculate as to why eukaryotes have either a) much more complex promoter and enhancer regions than prokaryotes or b) intron exon structure while prokaryotes do not. Please answer a and b if possible
List examples for each of the following. 1. Lost benefits associated with seasonal unemployment. 2. Lost...
List examples for each of the following. 1. Lost benefits associated with seasonal unemployment. 2. Lost benefits associated with frictional unemployment. 3. Lost benefits associated with structural unemployment.
3) A researcher is interested in studying whether or not baseball players are more superstitious than...
3) A researcher is interested in studying whether or not baseball players are more superstitious than people in general. The population has an average score of 4.3 (SD = 1.9) on the superstitious scale. A sample of 36 baseball players scored an average of 4.7 on the superstitious scale. What does the distribution of sample means for this scenario consist of? What would we conclude and explain your decision using the distribution of sample means in your explanation.
Choose the best answer that matches each statement below. Some choice may be used more than...
Choose the best answer that matches each statement below. Some choice may be used more than once, and some choices may not be used at all. Each question has one correct answer. A _____ is formed when two or more elements are combined in a chemical reaction. First to develop and atomic theory. A _____ change results in the formation of a new substance. He is credited with the discovery of the proton and electron. ______ cannot be broken down...
1. List and elaborate on the reasons that there more singles today than ever before. 2....
1. List and elaborate on the reasons that there more singles today than ever before. 2. Describe why more and more people are choosing to cohabit. 3. List and elaborate on some advantages and disadvantages of cohabitation compared to marriage, specifically regarding legal protections, financial stability, life satisfaction, and the potential impact on children.
Type your work (not more than 2 pages long) in MS Word in either font Arial...
Type your work (not more than 2 pages long) in MS Word in either font Arial or Verdana size 12. Spacing 1.5. 1. It seems that every time you listen to a Talk Radio station you hear someone telling the world what’s wrong with the younger generation. Here are two examples of this common criticism: “Our youth have an insatiable desire for wealth; they have bad manners and atrocious customs regarding dressing and their hair and what garments or shoes...
We feel that more than 10% of Americans lost someone due to inability to pay for...
We feel that more than 10% of Americans lost someone due to inability to pay for healthcare from 2014-2019. From 655 Americans we find 88 that did lose someone due to inability to pay for healthcare. Test the claim using a = 0.10 What is the claim? What are the null and alternate hypotheses? Will it be a one or two tailed test? Do we use z-scores or nothing? Why? Define the rejection region. Put it into words also. Summarize...
(2)   In the United States, more than 50% of banks have less than $100 million in...
(2)   In the United States, more than 50% of banks have less than $100 million in assets: T or F? (3)   In 1980, there were 14,404 commercial banks in the United States, but now there are 5,116 in 2020: T or F? (4)   The U.S. banking industry is highly concentrated compared with other industries in the United States or compared with the banking industry in other countries: T or F? (5)   The U.S. banking industry is one of the most...
List and discuss reasons why eukaryotes appear to have much more DNA than is necessary to...
List and discuss reasons why eukaryotes appear to have much more DNA than is necessary to code for all the possible proteins they have in their cells.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT