Question

Question: Write one SQL statement for the following question: Return number of players whose rating is...

Question: Write one SQL statement for the following question:

Return number of players whose rating is over 1000.

Background information:

This is a chess tournament management database that stores information about chess players, tournaments, sections, registrations, and pairings.

  • Each player has an ID, name, grade (0 to 12) and rating.
  • Each tournament has a number of sections. Each player can register for a section of a tournament
  • In each round of a tournament, players in the same section will be matched in pairs. Each pair of players will be assigned to a chess board to play. One plays white and the other plays black. The result could be white win (1:0), black win (0:1), or draw (0.5:0.5). Each player will play in each round (no knockout) and final score is sum of scores in each round. A player will play roughly equal number of games in white or black.

create table player(

pid int, -- player ID

pname varchar(50), -- name of player

grade int, --- grade of player, 0 to 12

rating int, -- rating of player, 0 to 3000

primary key (pid));

create table tournament(

tid int, -- tournament ID

tname varchar(50), --- name of tournament

tdate date, --- tournament date

primary key (tid));

create table section(

tid int, --- tournamnet id

sid int, -- section id

sname varchar(50), --- section name

maxgrade int, -- maximal grade allowed in section

mingrade int, --- minimal grade allowed in section

maxrating int, --- maximal rating allowed in section

minrating int, --- minimal rating allowed in section

primary key (tid, sid),

foreign key (tid) references tournament);

create table registration(

pid int, -- player id

tid int, -- tournament id

sid int, -- section id,

score number, -- score of player in the tournament, sum of score of each game, win 1, loss 0, draw 0.5,

---initial score is null

primary key (pid, tid),

foreign key (pid) references player,

foreign key (tid,sid) references section);

create table pairing(

bid int, --- board id, unique within a round in a tournament, two players will play on that board

tid int, --- tournament id

round int, -- round, 1, 2, 3, ...

wpid int, -- player ID who plays white

bpid int, -- player ID who plays black

wscore number, -- score for white player

bscore number, -- score for black player

primary key(bid,tid,round),

foreign key(tid) references tournament,

foreign key(wpid) references player,
foreign key(bpid) references player);

insert into player values(1,'Anna', 5, 1250);

insert into player values(2,'Dan', 6, 1320);

insert into player values(3,'Ella', 7, 1500);

insert into player values(4,'Nathan', 8, 1420);

insert into player values(5,'Rohan', 3, 920);

insert into player values(6,'Emily', 2, 620);

insert into player values(7,'Thomas', 3, 720);

insert into player values(8,'Andrew', 4, 820);

insert into tournament values(1,'Baltimore January Action',date '2017-1-7');

insert into tournament values(2,'MD Championship',date '2017-3-7');

insert into section values(1,1,'Junior Varsity', 12,0,1599,1200);

insert into section values(1,2,'Intermediate', 12,0,1199,600);

insert into section values(2,1,'Junior Varsity', 12,0,1599,1200);

insert into section values(2,2,'Intermediate', 12,0,1199,600);

insert into registration values(1,1,1,null);

insert into registration values(2,1,1,null);

insert into registration values(3,1,1,null);

insert into registration values(4,1,1,null);

insert into registration values(5,1,2,null);

insert into registration values(6,1,2,null);

insert into registration values(7,1,2,null);

insert into registration values(8,1,2,null);

insert into registration values(1,2,1,null);

insert into registration values(2,2,1,null);

insert into registration values(5,2,2,null);

insert into registration values(6,2,2,null);

--- tournament 1, round 1,

insert into pairing values(1,1,1,1,2,0,1);

insert into pairing values(2,1,1,3,4,0.5,0.5);

insert into pairing values(11,1,1,5,6,1,0);

insert into pairing values(12,1,1,7,8,0,1);

---- tournament 1, round 2

insert into pairing values(1,1,2,2,3,0,1);

insert into pairing values(2,1,2,4,1,1,0);

insert into pairing values(11,1,2,8,5,1,0);

insert into pairing values(12,1,2,6,7,0.5,0.5);

--- tournament 1, round 3

insert into pairing values(1,1,3,1,3,0.5,0.5);

insert into pairing values(2,1,3,4,2,1,0);

insert into pairing values(11,1,3,5,7,1,0);

insert into pairing values(12,1,3,8,6,0.5,0.5);

commit;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*counting player name from Player table*/
/* Count is the function which helps to count the number of records.
AS is used to give Alias name */

SELECT COUNT(pname) As PlayerCount FROM player
/* Filtering data based on rating.
> symbol helps to get all players of rating 1000*/

WHERE rating > 1000;

Output:
PlayerCount
5

Add a comment
Know the answer?
Add Answer to:
Question: Write one SQL statement for the following question: Return number of players whose rating is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use the SQL statements provided to create your tables. Write one SQL statement for each of...

    Use the SQL statements provided to create your tables. Write one SQL statement for each of the following problems. You can only use the conditions listed in the tasks. E.g., in task 1, you cannot manually look up pid of Information Systems undergraduate program. Here is the given code: drop table textbook_schedule cascade constraints; drop table textbook_author cascade constraints; drop table schedule cascade constraints; drop table course cascade constraints; drop table textbook cascade constraints; drop table author cascade constraints; drop...

  • Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring...

    Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring 2019. Use an explicit cursor to print out the titles and prices of textbooks for these two courses. Sample code to create the tables: drop table textbook_schedule cascade constraints; drop table textbook_author cascade constraints; drop table schedule cascade constraints; drop table course cascade constraints; drop table textbook cascade constraints; drop table author cascade constraints; drop table teacher cascade constraints; drop table program cascade constraints;...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • Create three or more MySQL Data Control language (DCL) Statements using the Youth League Database. 1....

    Create three or more MySQL Data Control language (DCL) Statements using the Youth League Database. 1. A Create new user statement for the database 2. A statement that grants privileges to the new user 3. A statement that revokes privileges 1. A SQL Text File containing the SQL commands to create the database, create the table, and insert the sample test data into the table. 2. A SQL Text File containing the DCL SQL Statements. eted hemas Untitled Limit to...

  • Please write ONE SQL statement for each of the following tasks using the below tables. Note...

    Please write ONE SQL statement for each of the following tasks using the below tables. Note that you can only use conditions specified in the task description and cannot manually look up data and add conditions. Task 1: return title of textbooks with price over $100. Task 2: return number of courses sections scheduled for each year and semester. Please return year, semester, and number of courses. Task 3: Return names of all courses in Information Systems undergraduate program. Task...

  • SQL I have a database CREATE TABLE vendor ( vid CHAR(2) NOT NULL, vname VARCHAR(25) NOT...

    SQL I have a database CREATE TABLE vendor ( vid CHAR(2) NOT NULL, vname VARCHAR(25) NOT NULL, PRIMARY KEY (vid) ); CREATE TABLE category ( catid CHAR(2) NOT NULL, catname VARCHAR(25) NOT NULL, PRIMARY KEY (catid) ); CREATE TABLE product ( pid CHAR(3) NOT NULL, pname VARCHAR(25) NOT NULL, price NUMERIC (7,2) NOT NULL, vid CHAR(2) NOT NULL, categoryid CHAR(2) NOT NULL, PRIMARY KEY (pid)); CREATE TABLE region ( rid CHAR NOT NULL, rname VARCHAR(25) NOT NULL, PRIMARY KEY (rid)...

  • /* I am executing following SQL statement for the below code but I am getting error....

    /* I am executing following SQL statement for the below code but I am getting error. Pls, upload screenshot after running it. SQL Statement: SELECT OfferNo, CourseNo FROM Offering WHERE OfferTerm = 'Sum' AND OfferYear = 2012 AND FacSSN IS NULL; */ CREATE TABLE STUDENT( StdSSN INT NOT NULL PRIMARY KEY, StdFName VARCHAR2(50), StdLName VARCHAR2(50), StdCity VARCHAR2(50), StdState VARCHAR2(2), StdZip VARCHAR2(10), StdMajor VARCHAR2(15), StdYear VARCHAR2(20) ); CREATE TABLE FACULTY( FacSSN INTEGER NOT NULL PRIMARY KEY, FacFName VARCHAR(50), FacLName VARCHAR(50), FacCity...

  • Database HW help!!!!!!! Provide the SQL statements for the following queries. (1) Provide the names and...

    Database HW help!!!!!!! Provide the SQL statements for the following queries. (1) Provide the names and phones of all swimmers currently in level (of id) 3. +-------+---------+---------------------------+ | FName | LName   | EMail                     | +-------+---------+---------------------------+ | Bobby | Khan    | theBKhan1 | | Clara | Johnson | ClaraJohnson_11 | +-------+---------+---------------------------+ 2 rows in set (0.00 sec) (2) Provide the names of swimmers who have signed up to participate in the event '100M Butterfly' of Meet id 1. +-------+---------+ | FName...

  • Problem 1. Please create the following tables for UMBC bookstore’s textbook management system with appropriate primary...

    Problem 1. Please create the following tables for UMBC bookstore’s textbook management system with appropriate primary keys & foreign keys. Please include drop table statements with cascade constraints before your create table statements so it is easier to grade your create table statements. E.g., suppose you will create table tab1, tab2, including the following before creating them: Drop table tab1 cascade constraints; Drop table tab2 cascade constraints; Assumptions: Each teacher can teach one or more scheduled course sections. Each scheduled...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT