0% found this document useful (0 votes)
129 views9 pages

Exercise DT

The document contains examples of SQL queries and solutions. It covers topics like selecting data, sorting results, using logical and comparison operators. The summaries provide high-level overviews of the types of SQL concepts and operations covered in each section without duplicating the specifics of the examples.

Uploaded by

Mahi Kishore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views9 pages

Exercise DT

The document contains examples of SQL queries and solutions. It covers topics like selecting data, sorting results, using logical and comparison operators. The summaries provide high-level overviews of the types of SQL concepts and operations covered in each section without duplicating the specifics of the examples.

Uploaded by

Mahi Kishore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Ex. No.

: Date :

Register No. : Name :

Limit Rows Selected

1. Using the Global Fast Foods database, retrieve the customer’s first name, last name, and
address for the customer who uses ID 456.
Solution:

2. Show the name, start date, and end date for Global Fast Foods' promotional item “ballpen and
highlighter” giveaway.
Solution:

3. Create a SQL statement that produces the following output:


Oldest
The 1997 recording in our database is The Celebrants Live in Concert
Solution:

4. The following query was supposed to return the CD title "Carpe Diem" but no rows were
returned. Correct the mistake in the statement and show the output.
SELECT produce, title
FROM d_cds
WHERE title = 'carpe diem' ;
Solution:
5. The manager of DJs on Demand would like a report of all the CD titles and years of CDs that
were produced before 2000.
Solution:

6. Which values will be selected in the following query?


SELECT salary
FROM employees
WHERE salary < = 5000;
a. 5000
b. 0 - 4999
c. 2500
d. 5
Solution:

7. Write a SQL statement that will display the student number (studentno), first name (fname),
and last name (lname) for all students who are female (F) in the table named students.
Solution:

8. Write a SQL statement that will display the student number (studentno) of any student who
has a PE major in the table named students. Title the studentno column Student Number.
Solution:
9. Write a SQL statement that lists all information about all male students in the table named
students.
Solution:

10. Write a SQL statement that will list the titles and years of all the DJs on Demand's CDs that
were not produced in 2000.
Solution:

11. Write a SQL statement that lists the Global Fast Foods employees who were born before
1980.
Solution:
Ex. No. : Date :

Register No. : Name :

Comparison Operators

1. Display the first name, last name, and salary of all Global Fast Foods staff whose salary is
between $5.00 and $10.00 per hour.
Solution:

2. Display the location type and comments for all DJs on Demand venues that are Private Home.
Solution:

3. Using only the less than, equal, or greater than operators, rewrite the following query:

SELECT first_name, last_name


FROM f_staffs
WHERE salary BETWEEN 20.00 and 60.00;
Solution:

4. Create a list of all the DJs on Demand CD titles that have “a” as the second letter in the title.
Solution:
5. Who are the partners of DJs on Demand who do not get an authorized expense amount?
Solution:

6. Select all the Oracle database employees whose last names end with “s”. Change the heading
of the column to read Possible Candidates.
Solution:

7. Which statement(s) are valid?


a. WHERE quantity <> NULL;
b. WHERE quantity = NULL;
c. WHERE quantity IS NULL;
d. WHERE quantity != NULL;
Solution:

8. Write a SQL statement that lists the songs in the DJs on Demand inventory that are type code
77, 12, or 1.
Solution:
Ex. No. : Date :

Register No. : Name :

Logical Comparisons and Precedence Rules

1. Execute the two queries below. Why do these nearly identical statements produce two
different results? Name the difference and explain why.
SELECT code, description
FROM d_themes
WHERE code >200 AND description IN('Tropical', 'Football', 'Carnival');
SELECT code, description
FROM d_themes
WHERE code >200 OR description IN('Tropical', 'Football', 'Carnival');
Solution:

2. Display the last names of all Global Fast Foods employees who have “e” and “i” in their last
names.
Solution:

3. “I need to know who the Global Fast Foods employees are that make more than $6.50/hour
and their position is not order taker.”
Solution:

4. Using the employees table, write a query to display all employees whose last names start with
“D” and have “a” and “e” anywhere in their last name.
Solution:
5. In which venues did DJs on Demand have events that were not in private homes?
Solution:

6. Which list of operators is in the correct order from highest precedence to lowest precedence?
a. AND, NOT, OR
b. NOT, OR, AND
c. NOT, AND, OR
Solution:

7. Who am I?
I was hired by Oracle after May 1998 but before June of 1999. My salary is less than $8000 per
month, and I have an “en” in my last name.
Solution:

8. What's my email address?


Because I have been working for Oracle since the beginning of 1996, I make more than $9000
per month. Because I make so much money, I don't get a commission
Solution:
Ex. No. : Date :

Register No. : Name :

Sorting Rows

1. In the example below, assign the employee_id column the alias of “Number.” Complete the
SQL statement to order the result set by the column alias.
SELECT employee_id, first_name, last_name
FROM employees;
Solution:

2. Create a query that will return all the DJs on Demand CD titles ordered by year with titles in
alphabetical order by year.
Solution:

3. Order the DJs on Demand songs by descending title. Use the alias "Our Collection" for the
song title.
Solution:

4. Write a SQL statement using the ORDER BY clause that could retrieve the information needed.
Solution:
5. Write a SQL statement using the employees table and the ORDER BY clause that could
retrieve the information in the following table. Return only those employees with
employee_id<125.

DEPARTMENT_ID LAST_NAME MANAGER_ID


90 Kochhar 100
90 King (null)
90 De Haan 100
60 Lorentz 103
60 Hunold 102
60 Ernst 103
50 Mourgos 100

Solution:

You might also like