MySQL

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesMySQL

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old November 6th, 2012, 07:27 AM
pragsmatic pragsmatic is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 pragsmatic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 19 sec
Reputation Power: 0
Smile Database Queries Questions

I had some questions about sql queries in my assignment for which I wrote answer and want some dbms guy to review it if it is correct !



Ques 1: You are provided with three tables in LMS schema in the following screen. The table details are:

1. Book(Title, Author, Publisher) - holds information about each of the book

2. Library(BranchCode, Librarian, Address) - contains details of the libraries

3. Book_library(BranchCode, Title, Copies) - has information about the books in all the libraries

You are required to write an SQL Query based on the tables given.
You are required to write an SQL Query to get the names of the branches that hold more than one copy of the book "The Alchemist".

Note 1: The column(s) to be displayed in the result or output should be BranchCode only.

Note 2: While writing the SQL query, you are required to write the table name as schemaname.tablename (For example employee.projectDetails where employee is schemaname and projectDetails is tablename).

Answer: select distinct BranchCode
from LMS.Book_Library with(nolock)
where Title = 'The Alchemist'
and copies > 1




Ques 2: You are provided with Five tables in Assessments Schema in the following screen. The table details are:

1. Questions (QuestionID, QuestionDesc, Option1, Option2, Option3, Option4, Answer, DifficultyLevel, Marks, SubjectId, TopicId)
2. Subjects (SubjectID, SubjectName)
3. Topics (TopicID, TopicName, SubjectID)
4. Tests (TestID, TestName, TestDuration)
5. TestQuestions(TestID, QuestionID)

The database schema called Assessments is used as part of a portal that conducts various tests.
a. Questions table contains the set of test questions. Questions are all multiple-choice, single answer.
This table contains several fields:
QuestionID: Unique to a question (primary key)
QuestionDesc: Question description
Option1: Answer option-1 of the multiple choices
Option2: Answer option-2 of the multiple choices
Option3: Answer option-3 of the multiple choices
Option4: Answer option-4 of the multiple choices
Answer: Correct Answer (contains 1/2/3/4)
Difficulty Level: Contains one of the value 1/2/3/4/5 (1- Easiest, 5 - Hardest)
Marks: Marks for the question
SubjectID: Subject Id
TopicID: Topic Id.

b. Subjects table contains the set of subjects. Each subject forms a unique row in the table.
c. Topics table contains the set of topics. Each topic forms a unique row in the table and is mapped uniquely to one SubjectID.
d. Tests table contains the set of tests in the portal. Each test forms a unique row in the Tests table.
e. TestQuestions: A test contains 1-N questions. Each question of the test forms a unique row in the TestQuestions table.

You are required to write an SQL Query based on the tables given.
You are required to write an SQL query to get all the QuestionIDs of the topic T004.

Note1: The column(s) to be displayed in the result or output should be QuestionID only.
Note2: While writing SQL query, you are required to write the table name as schemaname.tablename (For example employee.projectDetails where employee is schemaname and projectDetails is tablename).

Answer:
select QuestionID
from assessments.Questions with(nolock)
where TopicID = 'T004'








Ques 3: You are provided with Five tables in Assessments Schema in the following screen. The table details are:

1. Questions (QuestionID, QuestionDesc, Option1, Option2, Option3, Option4, Answer, DifficultyLevel, Marks, SubjectId, TopicId)
2. Subjects (SubjectID, SubjectName)
3. Topics (TopicID, TopicName, SubjectID)
4. Tests (TestID, TestName, TestDuration)
5. TestQuestions(TestID, QuestionID)

The database schema called Assessments is used as part of a portal that conducts various tests.
a. Questions table contains the set of test questions. Questions are all multiple-choice, single answer.
This table contains several fields:
QuestionID: Unique to a question (primary key)
QuestionDesc: Question description
Option1: Answer option-1 of the multiple choices
Option2: Answer option-2 of the multiple choices
Option3: Answer option-3 of the multiple choices
Option4: Answer option-4 of the multiple choices
Answer: Correct Answer (contains 1/2/3/4)
Difficulty Level: Contains one of the value 1/2/3/4/5 (1- Easiest, 5 - Hardest)
Marks: Marks for the question
SubjectID: Subject Id
TopicID: Topic Id.

b. Subjects table contains the set of subjects. Each subject forms a unique row in the table.
c. Topics table contains the set of topics. Each topic forms a unique row in the table and is mapped uniquely to one SubjectID.
d. Tests table contains the set of tests in the portal. Each test forms a unique row in the Tests table.
e. TestQuestions: A test contains 1-N questions. Each question of the test forms a unique row in the TestQuestions table.

You are required to write an SQL Query based on the tables given.
You are required to write an SQL query to get all the QuestionIDs of the questions with 5 marks.

Note1: The column(s) to be displayed in the result or output should be 'QuestionID' only.
Note2: While writing SQL query, you are required to write the table name as schemaname.tablename (For example employee.projectDetails where employee is schemaname and projectDetails is tablename).

Answer:
select QuestionId
from Assessments.Questions with(nolock)
where Marks = '5'








Ques 4: A TV network has several channels. Each channel is in a particular language. Each channel has a number and a name. There are programs in the channel everyday and each program is for a certain duration in minutes. There are different packages comprising of a set of channels. A channel can be in one or more package. Each package has a cost in Indian Rupees.

Based on above description,you are provided with four tables in TV_Cable Schema in the following screen. The table details are:

1. Channels (ChannelNumber,ChannelName,Language)

2. Programs (ProgramID,ProgramName,Channelnumber,Duration,Cate gory)

3. Packages (PackageID, PackageName, Cost)

4. Package_Channel(PackageID,ChannelNumber)


You are required to write an SQL Query based on the tables given.
You are required to write an SQL query to get the names of the channels which broadcasts those programs which contains the word -Dance in their names.

Note1: The column(s) to be displayed in the result or output should be ChannelName only.

Note2: While writing the SQL query, you are required to write the table name as schemaname.tablename (For example employee.projectDetails where employee is schemaname and projectDetails is tablename).
Answer:
select distinct c.channelname
from tv_cable.channels c with(nolock),
tv_cable.programs p with(nolock)
where c.Channelnumber = p.channelnumber
and p.ProgramName like '%Dance%'





















Ques 5:
Soccer is a popular sport played between two teams. A team consists of 11 players. Each team has a goal keeper. The game is played on a rectangular field of grass.

Based on the above description, you are provided with six tables in Soccer Schema in the following screen. The table details are:

1. PlayerDetails
Columns: (PlayerID, LastName, FirstName, Phone, StateCode)
Description: This table gives personal details of each Player. Each player has a player ID and belongs to different states of a country. Each state has a state code associated to it.

2. StateDetails
Columns: (StateCode, StateName)
Description: Maps the state codes to its corresponding states of the country.

3. PlayerTeamDetails
Columns: (PlayerID, TeamID, TenureStartingYear, TenureEndingYear)
Description: This table gives information about each player and the team he is playing for. Each player plays for a team for a certain period of time.

4. TeamDetails
Columns: (TeamID, TeamName, Owner, Manager, Coach)
Description: This table contains details of each team. Every team has a unique TeamID, an Owner, a Manager and a Coach associated with it.

5. PlayerMatchDetails
Columns: (PlayerID, TeamID, MatchID, Goals)
Description: Gives details about the matches played by a team and the goals scored in the matches. Every match has a match id. Each team plays numerous matches. Number of goals scored by a player in a particular match is also displayed in the table.

6. MatchTeamDetails
Columns: (MatchID, Team1, Team2, TG1, TG2, GroundName, MatchDate)
Description: This table contains information about a match played between two teams i.e., team IDs of both the teams, the field in which the match was played, the date of the match played and goals scored by each team. Result of a match could be victory of a team against the other or a draw between both the teams. Note: TG1 implies total goals scored by Team1 and TG2 implies total goals scored by Team2 in a particular match.

You are required to write an SQL Query based on the tables given.
You are required to write an SQL query to get the player IDs of those whose first name is David.

Note 1 : The column(s) to be displayed in the result or output should be ‚??PlayerID‚?? only.

Note 2 : While writing the SQL query, you are required to write the table name as schemaname.tablename (For example employee.projectDetails where employee is schemaname and projectDetails is tablename).

Answer:
select distinct PlayerID
from Soccer.PlayerDetails with(nolock)
where FirstName = 'David'



Ques 6:
A store has a database where details of various suppliers are managed along with the items that they stock. The tables used include

a) Suppliers: Has details on the suppliers (Name, email and phone number).

b) Item-suppliers: Has details on how the supplier supplies for various items. The same supplier would have varying delivery lead times, prices, discounts, minimum and maximum order quantity for various items. Likewise the table stores the number and value of items he has supplied to date.

c) Addresses: This has details of the various addresses for suppliers. This gets used in the supplier address table.

d) Supplier Address: Stores details of the various addresses stored about the supplier. The address types are picked from the Ref_Address Types table.

e) Ref_Address Types: This table contains details of various address types and their description- General, HeadQuarters, Warehouse and Unknown.

f) Inventory Items: This table has details on the various brands and the level at which reorder must be done as also the reorder quantity.

g) Brands: This table has information on the various brands mapped onto an item
Total quantity of items delivered by supplier to date= sum of total quantity_supplied_to _date for all items supplied by them.

Total value supplied across items delivered by supplier to date= sum of value_supplied_to_date for all items supplied by them.

A supplier would supply multiple items. Likewise the data base contains information on multiple addresses for the same supplier (for the various address types). It is also possible for multiple suppliers to have the same address.

By using the above tables,Write an SQL statement to list all addresses which are shared by multiple suppliers. Please note that this does not include cases where the same address corresponds to two different address types for the same supplier.List address_ID, line_1, line_2, city, state, zip_code.
Write an SQL statement to list all addresses which are shared by multiple suppliers. Please note that this does not include cases where the same address corresponds to two different address types for the same supplier.List address_ID, line_1, line_2, city, state, zip_code.

Note 1: The corresponding columns in the result must be called address_ID, line_1, line_2, city, state, zip_code

Note 2: While writing SQL query, you are required to write the table name as schemaname.tablename (For example Supplier.Supplier_Addresses where Supplier is schemaname and Supplier_Addresses is tablename).


Answer:
select distinct a.address_ID,a.line_1,a.line_2,a.city,a.state,a.zi p_code
from Supplier.Addresses a with(nolock),
Supplier.Supplier_Addresses s with(nolock)
where a.address_ID = s.address_ID
and (select count(address_id) from Supplier.Supplier_Addresses where address_id = s.address_id) > 1




Ques 7:
A retail store stocks multiple products inclusive of food, furniture, electronics and pet products and provides home delivery services against orders. The delivery is handled by its employees. The store has details stored on customers and tracks their orders, its employees who deliver products against these orders and suppliers who restock the products.

The key tables in the schema include

a) Customers: This table has customer level details.

b) Employees: This table has details on employees working at the store.

c) Suppliers: This table has details on the suppliers restocking products at the store.

d) Orders: This table has details on the various orders made.

e) Addresses: data on the various addresses for customers and employees.

f) Products: This has product level details.

g) Order_items: Listing the number of items of each product in an order. An order will include multiple products and 1 or more units of each product in the order. Hence number of items is =quantity of product 1+quantify of product 2+quantify of product 3 etc.

h) Deliveries: This table has details on deliveries against orders made.

i) Customer_Addresses: This table has address details of all customers.

Total value of an order= price of product 1* quantity of product 1+ price of product 2* quantity of product 2+ price of product 3* quantity of product 3 etc.

By using the above tables, write an SQL statement to list the order(s) that have been kept outstanding for the maximum duration of time.
Write an SQL statement to list the order(s) that have been kept outstanding for the maximum duration of time.

Note 1: The name of the column must be order_id

Note 2: While writing SQL query, you are required to write the table name as schemaname.tablename (For example Retail_Store.Orders where Retail_Store is schemaname and Orders is tablename).

Answer:
select distinct order_id
from Retail_Store.Orders with(nolock)
where order_status_code = 'open'
and paid_for_yn = 'No'

Ques 8:
A car dealership in the Minneapolis-St Paul area of Minnesota, US has presence in multiple branch locations in the area. Each of the branch locations has a branch manager and a set of salespeople. A single location would have multiple vehicles.

The dealership stocks cars from various leading manufacturers. The dealership also has data on the features available in each car. Some cars have multiple features, while other cars might not have any features.

The following are the tables in the schema

a) Branches: This table has data on the branch code, branch name and branch manager code at each location.

b) Sales_People: This table has detail on the sales person code, branch location and sales person name and contact details. A single branch will have multiple sales people mapped to it.

c) Car_Manufacturers: This table has detail on car manufacturers and relationships the dealership has with them.

d) Vehicles: This table has details on individual vehicles- manufacturer name and color

e) Inventory: This table captures detail of the cars present in each location. The inventory_ID maps every vehicleID to a single branch location

f) Actual_Car_Features: This table has details on multiple features mapped to a single vehicle. A car might have none, one or multiple features.

By using the above tables, write an SQL statement to list all the salespersons who belong to the Plymouth branch (List sales_Person_FirstName, sales_Person_LastName)

Write an SQL statement to list all the salespersons who belong to the Plymouth branch (List sales_Person_FirstName, sales_Person_LastName)

Note 1: The corresponding columns in the result must be called sales_Person_FirstName and sales_Person_LastName.

Note 2: While writing SQL query, you are required to write the table name as schemaname.tablename (For example Dealership.Branches where Dealership is schemaname and Branches is tablename).

Answer:
Select sp.Sales_Person_FirstName,
sp.Sales_Person_LastName
from Dealership.Sales_People sp with(nolock),
Dealership.Branches b with(nolock)
where sp.Branch_Location = b.Branch_Location
and b.Branch_Name = 'Plymouth'

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesMySQL > Database Queries Questions


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap