Homework1Solution
.txt
keyboard_arrow_up
School
Purdue University *
*We aren’t endorsed by this school
Course
348
Subject
Computer Science
Date
Apr 3, 2024
Type
txt
Pages
9
Uploaded by MegaTitanium11932
CS 348 - Homework 1: SQL (Joins, Aggregations, Set Operators)
(100 Points)
Spring 2024
Due on: 1/26/2024 at 11:59 pm This assignment is to be completed by individuals. There will be a 10% penalty if the homework is submitted 24 hours after the due date, a 20% penalty if the homework is submitted 48 hours after the due date, or a 30% penalty if the homework is submitted 72 hours after the due date. The homework will not be accepted after 72 hours, as a solution will be posted by then.
Submission Instructions: Submit your answers using the hw1.py skeleton file included with this assignment. The python file is read by the autograder. It is important to have a syntax-error free file. Your query result should have the same attributes(columns) exactly in the same order as the expected result shown in each question. However, the rows can
be in any order unless a specific order is required by the question. Column headers
can be different. Before submitting your Python file, execute the file using the command: Python3 hw1.py The output should contain all of your queries. Getting the correct output ensures that the autograder will be able to read your queries.
The homework will be submitted in Gradescope. Make sure you submit the correct file
(hw1.py). The Homework 1 lead TA will announce in Ed when the Gradescope submission
is open. Meanwhile, you can test your queries using the database included with this
homework.
Database instructions:
For this assignment, use SFBikeShare SQLite database included with this assignment.
You can open the database by simply typing .open SFBikeShare in the SQLite shell. For a readable layout in SQLite shell, run the commands .mode column .headers on
Grading:
This assignment will be auto-graded using SQLite. You are highly encouraged to use SQLite shell to test your queries before submitting your assignment. Grading will use a different database instance than the one given to students to test their queries. Therefore, make sure your queries are robust and that they work on any data instance. There is no partial credit in this homework.
===================================================================
Database: We will use the San Francisco Bike share database. Only part of the data is included with this homework.
Database Schema:
CREATE TABLE station ( // bike stations
id INTEGER PRIMARY KEY,
name TEXT,
lat NUMERIC,
long NUMERIC,
dock_count INTEGER,
city TEXT,
install_date TEXT);
CREATE TABLE station_status ( // the number of available bikes and docks in a station at a given date and time
id integer primary key autoincrement,
station_id INTEGER, // foreign key to station.id
bikes_available INTEGER,
docks_available INTEGER,
time TEXT);
CREATE TABLE trip (
id INTEGER PRIMARY KEY,
duration INTEGER,
start_station_id INTEGER, // foreign key to station.id
end_station_id INTEGER, // foreign key to station.id
bike_id INTEGER,
subscription_type TEXT, zip_code INTEGER, start_d Text, // start date and time of trip
end_d Text // end date and time of trip
);
CREATE TABLE daily_weather (
id integer primary key autoincrement,
date TEXT,
max_temperature_f INTEGER,
mean_temperature_f INTEGER,
min_temperature_f INTEGER,
max_dew_point_f INTEGER,
mean_dew_point_f INTEGER,
min_dew_point_f INTEGER,
max_humidity INTEGER,
mean_humidity INTEGER,
min_humidity INTEGER,
max_sea_level_pressure_inches NUMERIC,
mean_sea_level_pressure_inches NUMERIC,
min_sea_level_pressure_inches NUMERIC,
max_visibility_miles INTEGER,
mean_visibility_miles INTEGER,
min_visibility_miles INTEGER,
max_wind_Speed_mph INTEGER,
mean_wind_speed_mph INTEGER,
max_gust_speed_mph INTEGER,
precipitation_inches INTEGER,
cloud_cover INTEGER,
events TEXT,
wind_dir_degrees INTEGER,
zip_code INTEGER);
Notes:
- For all questions, include all columns shown in the expected result.
- Use the round function to round to two decimal places (unless the expected result
of a query has a different number of decimal places).
All questions have the same number of points (100/13)
=======================================
1) List trips with id number is less than or equal 7450. Trips for id <= 7450
Select t.id, start_station_id, name, start_d, end_d, duration
FROM trip t join station s on t.start_station_id = s.id
WHERE t.id <= 7450;
Expected Result:
id start_station_id name start_d end_d duration
---- ---------------- --------------------------------------- ---------------- ---------------- --------
7442 75 Mechanics Plaza (Market at Battery) 2013-09-01 00:11 2013-09-01 00:36 1508
7443 75 Mechanics Plaza (Market at Battery) 2013-09-01 00:12 2013-09-01 00:37 1513
7444 66 South Van Ness at Market 2013-09-01 00:19 2013-09-01 00:41 1345
7445 75 Mechanics Plaza (Market at Battery) 2013-09-01 00:21 2013-09-01 00:36 931
7446 25 Stanford in Redwood City 2013-09-01 00:23 2013-09-01 00:25 159
7447 66 South Van Ness at Market 2013-09-01 00:24 2013-09-01 00:42 1033
7448 69 San Francisco Caltrain 2 (330 Townsend) 2013-09-01 00:29 2013-09-01 00:35 323
7449 56 Beale at Market 2013-09-01 00:38 2013-09-01 00:52 825
7450 56 Beale at Market 2013-09-01 00:38 2013-09-01 00:52 819
======================================
2) Modify the previous query to add the name of the destination station (end station). Note that you will need two joins (connections) with the station table.
origin_station start_d duration destination_station
--------------------------------------- ---------------- -------- ---------------------------------------
Mechanics Plaza (Market at Battery) 2013-09-01 00:11 1508 Beale at Market
Mechanics Plaza (Market at Battery) 2013-09-01 00:12 1513 Beale at Market
South Van Ness at Market 2013-09-01 00:19 1345 Harry Bridges Plaza (Ferry Building)
Mechanics Plaza (Market at Battery) 2013-09-01 00:21 931 Mechanics Plaza (Market at Battery)
Stanford in Redwood City 2013-09-01 00:23 159 Franklin at Maple
South Van Ness at Market 2013-09-01 00:24 1033 Harry Bridges Plaza (Ferry Building)
San Francisco Caltrain 2 (330 Townsend) 2013-09-01 00:29 323 San Francisco Caltrain 2 (330 Townsend)
Beale at Market 2013-09-01 00:38 825 Harry Bridges Plaza (Ferry Building)
Beale at Market 2013-09-01 00:38 819 Harry Bridges Plaza (Ferry Building)
Select s1.name as origin_station, start_d, duration, s2.name as destination_station
FROM trip t join station s1 on t.start_station_id = s1.id
join station s2 on t.end_station_id = s2.id
WHERE t.id <= 7450;
======================================
3)
Count the number of trips between every pair of stations. Keep only pairs of stations with 10 or more trips. Show the average trip duration between a pair of stations as well.
name name cnt
avg_duration
------------------------------------ ---------------------------------------- ---
------------
Davis at Jackson Davis at Jackson 10 5404.80
Embarcadero at Bryant Embarcadero at Sansome 10 1349.60
Harry Bridges Plaza (Ferry Building) San Francisco Caltrain (Townsend at 4th) 10 1477.10
Powell at Post (Union Square) Powell at Post (Union Square) 11 7733.73
Embarcadero at Sansome Embarcadero at Sansome 12 8081.08
Harry Bridges Plaza (Ferry Building) Harry Bridges Plaza (Ferry Building) 12 5274.67
Powell at Post (Union Square) Harry Bridges Plaza (Ferry Building) 12 858.08
Harry Bridges Plaza (Ferry Building) Embarcadero at Vallejo 14 1157.21
Embarcadero at Vallejo Harry Bridges Plaza (Ferry Building) 16 3212.38
Harry Bridges Plaza (Ferry Building) Embarcadero at Sansome 18 1435.44
Select s1.name, s2.name, count(*) trip_count, round(avg(duration), 2) as avg_duration
FROM trip t join station s1 on t.start_station_id = s1.id
join station s2 on t.end_station_id = s2.id
GROUP BY s1.name, s2.name
HAVING trip_count >= 10
ORDER BY trip_count; ============================
4) The trip table includes data for two days only. Compute the average max_tempreature and number of trips in these days. You will have to use the date() function to extract the date part in the date and start_d attributes in the trip and weather tables, respectively.
Select date, avg(max_temperature_f) as avg_temp, count(distinct t.id) as number_trips
from daily_weather w join trip t on date(w.date) = date(t.start_d)
group by date
order by avg_temp desc;
date avg_temp number_trips
---------- -------- ------------
2014-09-01 85.8 368
2013-09-01 79.2 706
===============================================
5) The station_status table includes stats (bikes_available and docks_available)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
SQL QUERIES
Employees(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE,JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID,DEPARTMENT_NAME)Department(DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID)Location(LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID)
Write a Query in SQL to delete the record of all those cities where city name ends with b fromlocations table.
arrow_forward
SQL QUERIES
Employees(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE,JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID,DEPARTMENT_NAME)Department(DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID)Location(LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID)
Write a query in SQL to display the DEPARTMENT_NAME of all those Departments whoseDEPARTMENT_ID is greater than the DEPARTMENT_ID of Physics department.
Write a Query in SQL to show the FIRST_NAME of all those employees whose salary is lessthan the salary of all those employees whose MANAGER_ID is 101 or 102.
arrow_forward
Write a PL/SQL block that uses searched CASE statement to classify students based on their scores in a certain test according to the following table:
Score
Action
>= 90
A scholarship is given
80-89
A certificate is given
70-79
A training course is recommended
<70
The course should be repeated
Write the searched CASE structure only.
arrow_forward
relation:
Book (BookID, Author, ISBN, Title)
Write a PL/SQL block of code that performs the following tasks:
Read a Book id provided by user at run time and store it in a variable.
Fetch the Author and title of the book having the entered id and store them inside two variables
Display the fetched book author and title.
arrow_forward
WorksOn Database:
Employee (EmployeeNumber, EmployeeName, BirthDate, Title, Salary, DepartmentNumber)
Project (ProjectNumber, ProjectName, Budget, DepartmentNumber) Department (DepartmentNumber, DepartmentName, ManagerNumber) WorksOn (EmployeeNumber, ProjectNumber, Responsibility, Hours) Questions:
1) Write an SQL query that returns the project number and name for projects with a budget no greater than $1,050,000.
2) Write an SQL query that returns all works on records where hours worked is less than 5 and the responsibility is 'Manager'.
3) Write an SQL query that returns the employees (number and name only) who have a title of 'EE' or 'SA' and make more than $50,000.
4) Write an SQL query that returns the employees (name and salary only) in department 'D1' ordered by decreasing salary.
5) Write an SQL query that returns the departments (all fields) ordered by descending department name.
arrow_forward
J
SHORTAND NOTATION FOR RELATIONAL SQL TABLES
Notation Example Meaning
Underlined A or A, B The attribute(s) is
(are) a primary key
Superscript name
of relation
AR or AR, BR The attribute(s) is
(are) a foreign key
referencing
relation R
As an example, the schema
R(A, B, C, D, ES)
S(F, G, H)
corresponds to the following SQL tables:
CREATE TABLE R
( A <any SQL type>,
B <any SQL type>,
C <any SQL type>,
D <any SQL type>,
E <any SQL type>,
PRIMARY KEY(A),
FOREIGN KEY (E) REFERENCES S(F)
);
CREATE TABLE S
( F <any SQL type>,
G <any SQL type>,
H <any SQL type>,
PRIMARY KEY(F))
EXERCISE
Consider the following relational schema, representing five relations describing shopping transactions and
information about credit cards generating them [the used notation is explained above].
SHOPPINGTRANSACTION (TransId, Date, Amount, Currency, ExchangeRate, CardNbrCREDITCARD, StoreIdSTORE)
CREDITCARD (CardNbr, CardTypeCARDTYPE, CardOwnerOWNER, ExpDate, Limit)…
arrow_forward
: Write SQL queries DDL Queries to implement the following Relational Model i.e. create the Nurse and Care_Center relations (including primary key and foreign key). Intelligently write data types. Show Output.
arrow_forward
SQL ( ORACLE SQL DEVELOPER ) :
THIS IS FIRST , SECOND AND THIRD TABLE for the Task 1 to solve :
create table author_45(
auth_name char(50),
gender char(1),
age number(3),
nationality char(50),
PRIMARY KEY (auth_name)
);
create table book_45(
isbn number(10),
title char(50),
ver_no number(2),
publisher char(50),
PRIMARY KEY (isbn)
);
create table writtenBy_45(
isbn number(10),
auth_name char(50),
yr_published number(4),
price number(3),
no_copy number(4),
PRIMARY KEY (isbn,auth_name),
foreign key (isbn) references book_45,
foreign key (auth_name) references author_45
);
insert into author_45 values ('Benoit','F',42,'French');
insert into author_ 45 values ('Antonini','M',33,'Italian');
insert into author_ 45 values ('McAven','F',31,'Australian');
insert into author_ 45 values ('Williams','M',90,'British');
insert into book_45 values (101,'atabases',1,'Possum');
insert into book_45 values (202,'SQL Primer',2,'Hall');
insert into book_45 values…
arrow_forward
Write the appropriate SQL query for each of the following questions:
1) Display details of ALL the clubs running by the college
2) Display the details of the IT club (IT is the name of the club)
arrow_forward
pls help me : Write SQL queries to create tables with keys and relations corresponding to each of the following question
arrow_forward
SQL QUERIES
Employees(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID)Department(DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID)A: Write a query in SQL to display the minimum, maximum salary and DEPARTMENT_ID of all thosedepartments whose minimum salary is greater than 4000 in ascending order.
B: Write a Query in SQL to display characters only from 2 to 5 of “Last_Name” from Employees table.
C: Write a query in SQL to display the HIRE_DATE of every employee in following format.Format: 11-july-2019
arrow_forward
SQL QUERIES
Employees(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID)Department(DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID)A: Write a query in SQL to display the minimum, maximum salary and DEPARTMENT_ID of all thosedepartments whose minimum salary is greater than 4000 in ascending order.
arrow_forward
help me with database sql exercise
arrow_forward
Write the appropriate SQL query for each of the following questions:
Display the number of students acting in ‘Radio Club’
Display the sum of fees of activities organized by the IT club
arrow_forward
Write the appropriate SQL query for each of the following questions:
Display the number of students acting in ‘Radio Club’
Display the sum of fees of activities organized by the IT club
arrow_forward
Database course:
Write SQL queries to do the following
A. List names of IT students.
B. List titles of courses of type E.
C. Display the results of student with ID 201006
D. List student names and the courses they took.
E. List total credits that student with ID 201002.
arrow_forward
Write the appropriate SQL query for each of the following questions:
A) Display ALL the activities organized by the IT club
B) Display the number of students who are acting in each club.
arrow_forward
Given the following relation:
Book (BookID, Author, ISBN, Title)
Write a PL/SQL block of code that performs the following tasks:
Read a Book id provided by user at run time and store it in a variable.
Fetch the Author and title of the book having the entered id and store them inside two variables
Display the fetched book author and title.
arrow_forward
SQL QUERIES
Employees(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID)Department(DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID)B: Write a Query in SQL to display characters only from 2 to 5 of “Last_Name” from Employees table.
arrow_forward
sql
Employees(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID)Department(DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID)A: Write a query in SQL to display the minimum, maximum salary and DEPARTMENT_ID of all thosedepartments whose minimum salary is greater than 4000 in ascending order.
B: Write a Query in SQL to display characters only from 2 to 5 of “Last_Name” from Employees table.
C: Write a query in SQL to display the HIRE_DATE of every employee in following format.Format: 11-july-2019
arrow_forward
Write a PL/SQL block that uses a searched case statement to classify students based on their scores in a certain test according to
the following table.
Score Action
90
80-89 A certificate is given
70-79 A training course is recommended
<70
A scholarship is given
The course should be repeatcd
NB: Write the searched CASE structure only.
Use the editor to format your answer
arrow_forward
Q2:
Design Database for the following scenario and Write SQL queries.
Create an ERD for the following scenario. Suppose there is a grocery store near your house. Following can be
considered for ERD:
A grocery store may have more than one employee.
A grocery store has exactly one manager.
The manager has one or more sales men working under him.
Grocery store has more than one portion for the products.
• Each product has a barcode, name, expired date.
Many customers can busy many products, but each product is bought by only one customer.
Each customer will get an invoice for his /her purchase.
The bill invoice has an id.
arrow_forward
Student(Id, name, age, class, grade)
Write SQL server query to retrieve all the student in class 6
arrow_forward
Given the following relation:
Movie (MovieID, Title, Genre, Year)
Write a PL/SQL block of code that performs the following tasks:
Read a movie id provided by user at run time and store it in a variable.
Fetch the Genre and title of the movie having the entered id and store them inside two variables
Display the fetched movie Genre and title.
arrow_forward
PL/SQL Question
I need to build pl/sql block that prompts a user for the number of visitors each day for the past 5 days and then displays the average number of visitors per day.
For example;
day 1: 19
day 2: 21
day 3: 23
...
The avg number of visitors is: ___
like this.
arrow_forward
Assignment : PL/SQL Practice
Note: PL/SQL can be executed in SQL*Plus or SQL Developer or Oracle Live SQL.
Write an anonymous PL/SQL block that will insert a new doctor into the DOCTOR Verify that insert has been done successfully by issuing a select * from doctor.
arrow_forward
INFO 2303 Database Programming
Assignment : PL/SQL Practice
Note: PL/SQL can be executed in SQL*Plus or SQL Developer or Oracle Live SQL.
Write an anonymous PL/SQL block that will delete all patients for doctors that works in the Family Practice Verify that patients have been deleted accordingly. Then do a select * from patients where doc_id = (select doc_id from doctor where area = ‘Family Practice’. You should get no rows.
arrow_forward
Part II (50 points, each problem is worth 5 points)
Write SQL queries for the following database:
id
Customers
name
email
id
Categories
name
Ho
Ho
8 Orders
id
customer_id
B
id
Products
category_id
name
price
но
HO
Order_Product
id
order_id
product_id
quantity
1. Display all customers whose email is null or ends with 'fiu.edu' or 'gmail.com'
2. Display the number of orders placed by a customer whose name is ‘Jason Bourne'
(assume there is only one customer with this name).
3. Insert a new product (category_id = 1, name = 'apple', price = 3.00) into the product
table. Assume Products.id has a default value.
4. Create the Order_Product table as follows: id is the primary key and its data type is
serial, quantity is an integer which doesn't allow null, order_id and product_id are
foreign keys and will be set to null on delete.
5. Display the average price of all the products. For example, there are only three
products in the database with a price of 7, 8 and 9. Then the average price would…
arrow_forward
In SQL
This sample database consists of the following tables(see image for tables and there is one more at the bottom in this text):• Customers: stores customer’s data• Products: stores a list of scale model cars• ProductLines: stores a list of product line categories• Orders: stores sales orders placed by customers• OrderDetails: stores sales order line items for each sales order• Payments: stores payments made by customers based on their accounts• Employees: stores all employee information as well as the organization structuresuch as who reports to whom• Offices: stores sales office data
Write SQL code for the following:We want to add a new sale order for the customer (customerNumber = 145) in thedatabase. The steps of adding a sale order are described as follows:(1) Get latest sale order number from “orders” table, and use the next sale ordernumber as the new sale order number(2) Insert a new sale order into “orders” table for the customer (customerNumber =145). For this order, the…
arrow_forward
In SQL
This sample database consists of the following tables(see image for tables and there is one more at the bottom in this text):• Customers: stores customer’s data• Products: stores a list of scale model cars• ProductLines: stores a list of product line categories• Orders: stores sales orders placed by customers• OrderDetails: stores sales order line items for each sales order• Payments: stores payments made by customers based on their accounts• Employees: stores all employee information as well as the organization structuresuch as who reports to whom• Offices: stores sales office data
Write SQL code for the following:We want to add a new sale order for the customer (customerNumber = 145) in thedatabase. The steps of adding a sale order are described as follows:(1) Get latest sale order number from “orders” table, and use the next sale ordernumber as the new sale order number(2) Insert a new sale order into “orders” table for the customer (customerNumber =145). For this order, the…
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- SQL QUERIES Employees(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE,JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID,DEPARTMENT_NAME)Department(DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID)Location(LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) Write a Query in SQL to delete the record of all those cities where city name ends with b fromlocations table.arrow_forwardSQL QUERIES Employees(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE,JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID,DEPARTMENT_NAME)Department(DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID)Location(LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) Write a query in SQL to display the DEPARTMENT_NAME of all those Departments whoseDEPARTMENT_ID is greater than the DEPARTMENT_ID of Physics department. Write a Query in SQL to show the FIRST_NAME of all those employees whose salary is lessthan the salary of all those employees whose MANAGER_ID is 101 or 102.arrow_forwardWrite a PL/SQL block that uses searched CASE statement to classify students based on their scores in a certain test according to the following table: Score Action >= 90 A scholarship is given 80-89 A certificate is given 70-79 A training course is recommended <70 The course should be repeated Write the searched CASE structure only.arrow_forward
- relation: Book (BookID, Author, ISBN, Title) Write a PL/SQL block of code that performs the following tasks: Read a Book id provided by user at run time and store it in a variable. Fetch the Author and title of the book having the entered id and store them inside two variables Display the fetched book author and title.arrow_forwardWorksOn Database: Employee (EmployeeNumber, EmployeeName, BirthDate, Title, Salary, DepartmentNumber) Project (ProjectNumber, ProjectName, Budget, DepartmentNumber) Department (DepartmentNumber, DepartmentName, ManagerNumber) WorksOn (EmployeeNumber, ProjectNumber, Responsibility, Hours) Questions: 1) Write an SQL query that returns the project number and name for projects with a budget no greater than $1,050,000. 2) Write an SQL query that returns all works on records where hours worked is less than 5 and the responsibility is 'Manager'. 3) Write an SQL query that returns the employees (number and name only) who have a title of 'EE' or 'SA' and make more than $50,000. 4) Write an SQL query that returns the employees (name and salary only) in department 'D1' ordered by decreasing salary. 5) Write an SQL query that returns the departments (all fields) ordered by descending department name.arrow_forwardJ SHORTAND NOTATION FOR RELATIONAL SQL TABLES Notation Example Meaning Underlined A or A, B The attribute(s) is (are) a primary key Superscript name of relation AR or AR, BR The attribute(s) is (are) a foreign key referencing relation R As an example, the schema R(A, B, C, D, ES) S(F, G, H) corresponds to the following SQL tables: CREATE TABLE R ( A <any SQL type>, B <any SQL type>, C <any SQL type>, D <any SQL type>, E <any SQL type>, PRIMARY KEY(A), FOREIGN KEY (E) REFERENCES S(F) ); CREATE TABLE S ( F <any SQL type>, G <any SQL type>, H <any SQL type>, PRIMARY KEY(F)) EXERCISE Consider the following relational schema, representing five relations describing shopping transactions and information about credit cards generating them [the used notation is explained above]. SHOPPINGTRANSACTION (TransId, Date, Amount, Currency, ExchangeRate, CardNbrCREDITCARD, StoreIdSTORE) CREDITCARD (CardNbr, CardTypeCARDTYPE, CardOwnerOWNER, ExpDate, Limit)…arrow_forward
- : Write SQL queries DDL Queries to implement the following Relational Model i.e. create the Nurse and Care_Center relations (including primary key and foreign key). Intelligently write data types. Show Output.arrow_forwardSQL ( ORACLE SQL DEVELOPER ) : THIS IS FIRST , SECOND AND THIRD TABLE for the Task 1 to solve : create table author_45( auth_name char(50), gender char(1), age number(3), nationality char(50), PRIMARY KEY (auth_name) ); create table book_45( isbn number(10), title char(50), ver_no number(2), publisher char(50), PRIMARY KEY (isbn) ); create table writtenBy_45( isbn number(10), auth_name char(50), yr_published number(4), price number(3), no_copy number(4), PRIMARY KEY (isbn,auth_name), foreign key (isbn) references book_45, foreign key (auth_name) references author_45 ); insert into author_45 values ('Benoit','F',42,'French'); insert into author_ 45 values ('Antonini','M',33,'Italian'); insert into author_ 45 values ('McAven','F',31,'Australian'); insert into author_ 45 values ('Williams','M',90,'British'); insert into book_45 values (101,'atabases',1,'Possum'); insert into book_45 values (202,'SQL Primer',2,'Hall'); insert into book_45 values…arrow_forwardWrite the appropriate SQL query for each of the following questions: 1) Display details of ALL the clubs running by the college 2) Display the details of the IT club (IT is the name of the club)arrow_forward
- pls help me : Write SQL queries to create tables with keys and relations corresponding to each of the following questionarrow_forwardSQL QUERIES Employees(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID)Department(DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID)A: Write a query in SQL to display the minimum, maximum salary and DEPARTMENT_ID of all thosedepartments whose minimum salary is greater than 4000 in ascending order. B: Write a Query in SQL to display characters only from 2 to 5 of “Last_Name” from Employees table. C: Write a query in SQL to display the HIRE_DATE of every employee in following format.Format: 11-july-2019arrow_forwardSQL QUERIES Employees(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID)Department(DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID)A: Write a query in SQL to display the minimum, maximum salary and DEPARTMENT_ID of all thosedepartments whose minimum salary is greater than 4000 in ascending order.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education