Question

Having below tables: create table Student(sid char(10) primary key, sname varchar(20) not null, gpa float, major...

Having below tables:

create table Student(sid char(10) primary key,

sname varchar(20) not null, gpa float, major char(10), dob DATE);

create table Course(cno char(10) primary key,

cname varchar(20) not null, credits int, dept char(10));

create table Reg( sid references Student(sid) on delete cascade,

cno references Course(cno) on delete cascade,

grade char(2),

primary key (sid, cno));

questions

  1. For each course, display the number of students who got each grade, ordered by the course and the letter grade.
  2. List the current age in years for each student, ordered from youngest to oldest.
  3. Lets do a simple analytics query - for each major, list the number of students, minimum gpa, maximum gpa, average gpa, minimum age, maximum age and average age. Show GPA with 2 decimal points, age with no decimal points. You may find it useful to create a view with one of the previous queries for this one.

Homework Answers

Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 1:

SQL Query :

select cname,count(grade) from course,Reg
where
course.cno=Reg.cno
group by cname
order by cname,count(grade);

Explanation :Given query will join two tables course and Reg and will return the course name and number of students got the letter grade.

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

Question 2:

SQL Query :

select sid,sname,datediff(yy,convert(datetime, DOB),getdate()) as 'Age' FROM student
order by age;

Explanation :This query will return the age of the student.

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

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Know the answer?
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
Similar Questions
Create table Student (       ssn numeric primary key,       name char(50),       address varchar(100),       major  char(10)
Create table Student (       ssn numeric primary key,       name char(50),       address varchar(100),       major  char(10) ); create view CS_Student as             select ssn, name, address from student where major = 'CS'; create a trigger on this view. If a tuple is inserted into the view, then insert it into the base table. If a tuple is deleted from the view, then delete it from the base table.
Space X Bank CREATE TABLE Branch(BranchIDNumber VARCHAR(15) PRIMARY KEY NOT NULL, BranchName VARCHAR(6) NOT NULL, Address...
Space X Bank CREATE TABLE Branch(BranchIDNumber VARCHAR(15) PRIMARY KEY NOT NULL, BranchName VARCHAR(6) NOT NULL, Address VARCHAR(50) NOT NULL, City TEXT NULL, State CHAR(2) NULL, ZipCode INT(11) NOT NULL, OfficeNum VARCHAR(15) NOT NULL, FaxNum VARCHAR(15) NOT NULL); CREATE TABLE Employee(EmployeeIDNumber VARCHAR(15) NOT NULL,FirstName VARCHAR(35) NOT NULL, LastName VARCHAR(35) NOT NULL, Email VARCHAR(100) NOT NULL, BranchIDNumber VARCHAR(11) NOT NULL, FOREIGN KEY(BranchIDNumber) REFERENCES Branch(BranchIDNumber), JobTitle ENUM("Manager","Staff") NOT NULL, Salary DECIMAL(8, 2) NOT NULL, HomeNumber VARCHAR(13) NULL, CellNumber VARCHAR(13) NOT NULL); CREATE TABLE...
Perform SQL queries in the given data structure. write an SQL query that gives the number...
Perform SQL queries in the given data structure. write an SQL query that gives the number of courses taken for every student in the student table. For each instructor, show the instructor name and the number of sections that have been taught by that instructor. You do not need to include instructors who have never taught a section. List in order of decreasing the number of sections taught. Give the number of semester/year combinations in which sections have been offered....
-- Table construction (just 1 simplest possible way) CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY,...
-- Table construction (just 1 simplest possible way) CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY, animalType VARCHAR(20), breed VARCHAR(20) ); CREATE TABLE Owner ( ownerId VARCHAR(10) PRIMARY KEY, firstName VARCHAR(20), lastName VARCHAR(20) NOT NULL, homePhoneNumber VARCHAR(20), streetAddress VARCHAR(80), suburb VARCHAR(20), postcode VARCHAR(10) ); CREATE TABLE Pet ( petId VARCHAR(10) PRIMARY KEY, petName VARCHAR(20), sex CHAR(1) CHECK (sex IN ('M', 'F')), petTypeId VARCHAR(10) FOREIGN KEY REFERENCES PetType ); CREATE TABLE PetAndOwner ( ownerId VARCHAR(10), petId VARCHAR(10), PRIMARY KEY (ownerId, petId),...
Consider the following relational database:               STUDENT     (STDNO, SNAME, DEPTNO#)             &n
Consider the following relational database:               STUDENT     (STDNO, SNAME, DEPTNO#)               DEP                 (DEPTNO, DNAME)               COURSE        (CORSNO, CNAME, DEPTNO#, CMAX)               ENROLMENT       (STDNO#, CORSNO#, GRADE, EDATE) STUDENT.DEPTNO is the department number of the student. COURSE.DEPTNO is the department number that offers the course. ENROLMENT models the registrations of students in courses (M:M relationship) where the GRADE is the grade obtained by the student in the course. PART I : DATA DESCRIPTION LANGUAGE (DDL) Write DDL commands to create the four...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE TABLE Student (  sid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  address VARCHAR(20) NOT NULL,  major CHAR(2)); CREATE TABLE Professor (  pid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  department VARCHAR(10) NOT NULL); CREATE TABLE Course (  cid INT PRIMARY KEY,  title VARCHAR(20) NOT NULL UNIQUE,  credits INT NOT NULL,  area VARCHAR(5) NOT NULL); CREATE TABLE Transcript (  sid INT,  cid INT,  pid INT,  semester VARCHAR(9),  year YEAR,  grade CHAR(1) NOT NULL,  PRIMARY KEY (sid, cid, semester, year),  FOREIGN KEY (sid) REFERENCES Student...
With this code: CREATE TABLE STUDENT( StudentID integer, primary key StudentName char(25) NOT NULL) I am...
With this code: CREATE TABLE STUDENT( StudentID integer, primary key StudentName char(25) NOT NULL) I am getting the 1064 error about char(25) but don't know how to fix it in MySQL workbench.
Here are SQL declarations for three tables R, S, and T: CREATE TABLE R(e INT PRIMARY...
Here are SQL declarations for three tables R, S, and T: CREATE TABLE R(e INT PRIMARY KEY, f INT); CREATE TABLE S(c INT PRIMARY KEY, d INT REFERENCES R(e) ON DELETE CASCADE); CREATE TABLE T(a INT PRIMARY KEY, b INT REFERENCES S(c) ON DELETE CASCADE); Suppose R(e,f) contains tuples (1,0), (2,4), (3,5), (4,3), and (5,7). Suppose S(c,d) contains tuples (1,5), (2,2), (3,3), (4,5), and (5,4). Suppose T(a,b) contains tuples (0,2), (1,2), (2,3), (3,4), and (4,4). As a result of the...
CREATE TABLE Customers (Customer# NUMBER(4), LastName VARCHAR2(10) NOT NULL, FirstName VARCHAR2(10) NOT NULL, Address VARCHAR2(20), City...
CREATE TABLE Customers (Customer# NUMBER(4), LastName VARCHAR2(10) NOT NULL, FirstName VARCHAR2(10) NOT NULL, Address VARCHAR2(20), City VARCHAR2(12), State VARCHAR2(2), Zip VARCHAR2(5), Referred NUMBER(4), Region CHAR(2), Email VARCHAR2(30), CONSTRAINT customers_customer#_pk PRIMARY KEY(customer#), CONSTRAINT customers_region_ck CHECK (region IN ('N', 'NW', 'NE', 'S', 'SE', 'SW', 'W', 'E')) ); CREATE TABLE Orders (Order# NUMBER(4), Customer# NUMBER(4), OrderDate DATE NOT NULL, ShipDate DATE, ShipStreet VARCHAR2(18), ShipCity VARCHAR2(15), ShipState VARCHAR2(2), ShipZip VARCHAR2(5), ShipCost NUMBER(4,2), CONSTRAINT orders_order#_pk PRIMARY KEY(order#), CONSTRAINT orders_customer#_fk FOREIGN KEY (customer#) REFERENCES customers(customer#)); In...
-- Define the database CREATE TABLE Product ( ProdName VARCHAR2(10) NOT NULL, Price INTEGER NOT NULL,...
-- Define the database CREATE TABLE Product ( ProdName VARCHAR2(10) NOT NULL, Price INTEGER NOT NULL, CONSTRAINT PRODUCT_PK PRIMARY KEY (ProdName) ); CREATE TABLE Customer ( ID INTEGER NOT NULL, ProdName VARCHAR2(10), Rating INTEGER, CustName VARCHAR2(10), CONSTRAINT CUSTOMER_PK PRIMARY KEY (ID) ); CREATE TABLE Buys ( ID INTEGER NOT NULL, ProdName VARCHAR2(10) NOT NULL, Quantity INTEGER NOT NULL, CONSTRAINT BUYS_PK PRIMARY KEY (ID, ProdName) ); ALTER TABLE Buys ADD CONSTRAINT PRODUCT_BUYS_FK FOREIGN KEY (ProdName) REFERENCES Product (ProdName) NOT DEFERRABLE; ALTER...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT