26
BASKETBALL EXERCISE

Q1 - Show all the records in the basket ball player table select * from BSKT_BALL_PLAYER;

Embed Size (px)

Citation preview

Basketball exercise

Basketball exerciseQ1 - Show all the records in the basket ball player table

select * from BSKT_BALL_PLAYER;

Q1 - answer

Q2 - Show the last name and first name of the players.select player_lname, player_fname From BSKT_BALL_PLAYER;

Q2 with aliasselect player_lname as "Last Name", player_fname as "First Name"from BSKT_BALL_PLAYER;

Q3 -Order the above by descending lname then descending first name

select player_lname, player_fname from BSKT_BALL_PLAYERorder by player_lname DESC, player_fname DESC ;

Q3 - output

Q4 - Add the GPA to the output and sort the output by GPA only.

select player_lname, player_fname, gpafrom BSKT_BALL_PLAYERorder by gpa;

Q5 - Show the unique graduation years of all the players.

select distinct year_graduation from BSKT_BALL_PLAYER;

What if I dont use the keyword distinct?

Some of the values are duplicated, like 2009, 2010, 2009

Number of records goes from 13 to 19

Q6 - Show the players first and last name and college if the college is 1. Order the output by players last name.

select player_fname, player_lname, collegefrom BSKT_BALL_PLAYER where COLLEGE = 1order by player_lname;

Q 6 answer

But is college_id what they are looking for?select player_fname, player_lname, college_name, college_idfrom BSKT_BALL_PLAYER, collegewhere COLLEGE = 1 and college = college_idorder by player_lname;

Q6 answer revised

Q7 - Show the players first and last name , college, gpa if the college is 1 and the students GPA is greater than 3.5. Order the output by players last name.

No QC

With QC

Q 8 - Show the players first and last name , college, gpa if the college is 1 and the students GPA is greater than 3.5 OR the students jersey is #13 Order the output by players last name.

Key to this oneMake sure to add parentheses!!!!

Q 9 Display the players first and last name , college, gpa if the college is 1, 2, 3, 4, or 5. Order the output by players last name.

Remember the in operatorselect player_fname, player_lname, college_name gpa, jersey_number, collegefrom BSKT_BALL_PLAYER, collegewhere COLLEGE in (1, 2, 3, 4, 5) andcollege = college_idorder by player_lname;

OR select player_fname, player_lname, college_name, gpa, jersey_number, collegefrom BSKT_BALL_PLAYER, collegewhere COLLEGE = 1 or college =2 or college =3 or college = 4 or college= 5 andcollege = college_idorder by player_lname;

Q10 Show the players names born between 1/1/1984 and 3/5/1986. Order by player last name.

Remember the to_date function!select player_fname, player_lname, dobfrom BSKT_BALL_PLAYERwhere dob between to_date ('01/01/1984', 'mm/dd/yyyy') and to_date ('03/05/1986', 'mm/dd/yyyy')order by player_lname;

Q 11 Display the players first and last name , college, and gpa if the college is Temple University. Order the output by players last name.

select player_fname, player_lname, college, gpa, jersey_numberfrom BSKT_BALL_PLAYER, collegewhere COLLEGE_name = 'Temple University'and COLLEGE_ID= COLLEGE order by player_lname;