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 (Oracle live SQL)

  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

1) SELECT grade, cno, count(distinct sid) FROM Reg GROUP BY cno, grade ORDER BY cno, grade;

2) SELECT months_between(TRUNC(sysdate), to_date(dob, 'DD-MON-YYYY') )/12 as age FROM Student ORDER BY age;

3) SELECT major, count(distinct sid), round(min(gpa), 2), round(max(gpa), 2), round(avg(gpa), 2), min(months_between(TRUNC(sysdate), to_date(dob, 'DD-MON-YYYY') )/12), max(months_between(TRUNC(sysdate), to_date(dob, 'DD-MON-YYYY') )/12), avg(months_between(TRUNC(sysdate), to_date(dob, 'DD-MON-YYYY') )/12) FROM Student;

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
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 For each course, display the number of students who got each grade, ordered by the course and the letter grade. List the current age in...
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...
Create table employee( Employeenumber int NOT NULL IDENTITY (1,1), Firstname Char (25) Not null, lastname Char...
Create table employee( Employeenumber int NOT NULL IDENTITY (1,1), Firstname Char (25) Not null, lastname Char (25) Not null, department Char (35) Not null default "Human Resources", position Char (35) Not null, supervisor int Not null, officephone Char (12) Not null, emailaddress varchar (100) Not null unique, Constraint employee_pk primary key(employeenumber), Constraint Emp_depart_fk foreign key (department) References department(departmentname) on update cascade, constraint emp_super_fk foreign key (Supervisor) references employee(employeenumber) ); Bolded section Line 2 is coming back with an error
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....
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...
-- 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),...
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...