0% found this document useful (0 votes)
4 views

assignment 3 ORACLE

The document outlines a series of SQL assignment tasks that involve querying customer and product data from a database. Tasks include displaying highest and lowest product prices, filtering customer details based on specific criteria, and performing calculations and updates on product information. Additionally, it covers various SQL functions and concepts such as NULLIF, TO_CHAR, and temporary tables.

Uploaded by

sagarthube
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)
4 views

assignment 3 ORACLE

The document outlines a series of SQL assignment tasks that involve querying customer and product data from a database. Tasks include displaying highest and lowest product prices, filtering customer details based on specific criteria, and performing calculations and updates on product information. Additionally, it covers various SQL functions and concepts such as NULLIF, TO_CHAR, and temporary tables.

Uploaded by

sagarthube
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/ 5

Assignment 3

1) Display the highest product price for product type price.

Output should be as follow.

Highest_prod_price
1499708

2) Display the lowest product price for company name Ashok Leyland.

Highest_prod_price
536129

3) Display the result from customer_details table Whose first name starts with H/h and while
displaying the result add 4 month in purchase date.

Output should be as below.

Customer_details
Cust_id First_name Last_name Product_id Quantity Purchase_date
5007 Hannah Dyer 2017 1 23-Nov-2001
5008 Heather Edmunds 2018 3 24-Nov-2001
5020 Heather Edmunds 1008 1 5-dec-2008
5021 Heather Edmunds 2024 1 6-dec-2008
5022 Heather Edmunds 2025 2 7-dec-2008

4) Find out the customer details whose first name starts with E or I and last name ends with r or s
and it may in any of the case(Capital/Small).

5) Write a query to select current month.(eg. August).

6) Write a query to get Customer Details whose first name is Grace.

Note: Name can be any of case. Like(Grace, gRacE, grACe) it should be return.

7) Write a query to get customer details whose last name is having more than 7 character and 5th
character is u/U.

8) Write a query to get all customer details as below.

Note: First character of first name in capital letter and last name together.

Customer_name
E Cornish
F Davidson
F Davies
F Dickens
G Dowd
G Duncan
9) Write a query to get customer details whose product_id or quantity is having null value.

10) List out the customer details who has purchase the vehicle in 2008 year.

11) Display the average product id from customer details who has purchase the vehicle in AUGUST
month.

12) Write a query to get difference between highest product price and lowest product price from
product_details table.

13) Explain cast function with help of examples.

14) Write a query to get customer details whose purchase year not equal to 2008,1995,2001.

15) What is global temporary table explain with help of example.

16) Write a syntax to create tables with primary key on two columns,

And unique key with two columns,

And Foreign key with ON DELETE SET NULL and ON DELETE CASCADE constraints.

Also write down point wise difference between Primary key, Unique key and Foreign key
constraints.

17) Write a query to get first not null value consider the following input.

First_name Last_name Customer_name


Null Null E Cornish
Faith Null F Davidson
Null Davies Null
Null Null F Dickens
Null Null G Dowd
null Duncan G Duncan

Output should be as below.

Customer_name
E Cornish
Faith
Davies
F Dickens
G Dowd
Duncan

18) Write a query to concatenate all the first_name,last_name and month name of purchase date
from customer details table. output should be as below.

Customer_Name Purchase Month


Emma Cornish July

19) Write query to get total number of quantity sold in July 2001.
20) Write a query to get total number of records are there for Quantity column with null value and
without null values.

Note: understand the difference between Count(*),Count(quantity) and Count(Distinct quantity).

21) Write a query to display difference between current date and purchase date in years.

22) Write a query to get all product details with grade of product price as below.

If product price is <= 50000 then Grade D

If product price is >= 50000 and <=100000 then Grade C

If product price is >= 100000 and <=120000 then Grade B

If product price is >= 120000 and <=180000 then Grade A.

Product Details
Product_id Company_name Product_type Product_name Prod_price Product_grade
1001 Ashok Leyland Bus 12M 744643 C Grade
1002 Ashok Leyland Bus 12M FESLF 1346136 A Grade
1003 Ashok Leyland Bus Viking 879128 C Grade
1004 Ashok Leyland Bus Cheetah 713266 C Grade

23) Write a query to display on which day customer has purchase the product.

Customer_Details
Cust_id First_name Last_name Product_id Quantity Purchase_date Purchase_day
5001 Emma Cornish 1001 1 17-Jul-1995 Monday
5002 Faith Davidson 1001 2 18-Jul-1995 Tuesday
5003 Felicity Davies 1013 1 19-Jul-1995 Wednesday
5004 Fiona Dickens 1014 Null 20-Jul-1995 Thursday
5005 Gabrielle Dowd 1015 1 21-Jul-2001 Friday

24) Write a query to see current user.

25) Write a query to get even record only.

Note: Only display 2nd,4th,6th,….. Records from customer details table.(Use ROWNUM).

26) Write a query to display today’s day.(Eg. Wednesday).

27) What is NULLIF Function explain with the help of examples.

28) Write a query to add 10 units in quantity and if quantity is null then it should be 10 only as
below.

Input Output
Quantity Updated Quantity
1 11
2 12
1 11
null 10
1 11
null 10
1 11
3 13

29) How to remove extra spaces from left and right side of first name column.

30) Write a query to get expected output.

Customer_name First_name Last_name


Emma Cornish Emma Cornish
Faith Davidson Faith Davidson
Felicity Davies Felicity Davies
Fiona Dickens Fiona Dickens
Gabrielle Dowd Gabrielle Dowd
Grace Duncan Grace Duncan

31) Write a query to replace 4th character with same character but 2 times as below.

First_name First_name
Emma Emmaa
Faith Faitth
Felicity Feliicity
Fiona Fionna
Gabrielle Gabrrielle
Grace Gracce

32) Explain TO_CHAR and TO_DATE functions with the help of examples.

33) Write a query to display customer details who has purchase the product in year 1995 or 2008
and first name should contains the ‘a’ character or 4th character of last name should be ‘s’.

34) Write a query to display records from customer details table who has purchase vehicle in current
month.

Note: like current month is march then who else purchase the vehicle in march.

35) Consider there is table with Date_details with day,Month and Year column insert the values from
Customer_details of Purchse_date column to Date_details as follows.

Purchase_date Day Month Year


24_Jul_2001 Tuesday july 2001
25_Jul_2001 Wednesday july 2001
26_Aug_2005 Sunday august 2005
27_Jul_2001 Friday july 2001
28_Jul_2001 Saturday july 2001
36) Update Prod_Info table as below.

Prod_Info
Product_Nmae Prod_Price Prod_Price_Grade
12M 744643 Null
12M FESLF 1346136 Null
Viking 879128 Null
Cheetah 713266 Null
Eagle 1499708 Null
Electric Bus 1206710 Null
Freedom 768974 Null
Hawk 628910 Null
Hybus 1058508 Null

Update table base on prod_price.

If prod_price is less than 10,00,000 then grade is B.

If prod_price is greater than 10,00,000 then grade is A.

Updated table should be as below.

Prod_Info
Product_Nmae Prod_Price Prod_Price_Grade
12M 744643 B
12M FESLF 1346136 A
Viking 879128 B
Cheetah 713266 B
Eagle 1499708 A
Electric Bus 1206710 A
Freedom 768974 B
Hawk 628910 B
Hybus 1058508 A

37) Write a query to get expected output as below.

First_name Last_name Customer_name


Emma Cornish Emma Cornish
Faith Davidson Davidson
Felicity Davies Davies
Fiona Dickens Fiona Dickens
Gabrielle Dowd Dowd
Grace Duncan Grace Duncan
Hannah Dyer Hannah Dyer
If the first name and last name together contains more than 12 characters then customer name
should be display only last name and if it is less than 12 character then display first name as well as
last name.

You might also like