Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
215 views

Module 4 Assignment - SQL

The document describes a module 4 assignment involving inbuilt and user-defined functions in SQL. It includes 3 tasks: 1) use MIN, MAX, and AVG functions to analyze an orders table, 2) create a user-defined function to multiply a number by 10, and 3) use a CASE statement to check if a number is less than, greater than, or equal to 200. Sample code and output is provided for each task.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
215 views

Module 4 Assignment - SQL

The document describes a module 4 assignment involving inbuilt and user-defined functions in SQL. It includes 3 tasks: 1) use MIN, MAX, and AVG functions to analyze an orders table, 2) create a user-defined function to multiply a number by 10, and 3) use a CASE statement to check if a number is less than, greater than, or equal to 200. Sample code and output is provided for each task.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Module-4 Assignment

Problem Statement:
You have successfully cleared your 3rd semester. In the 4th semester, you will work with inbuilt functions
and user-defined functions

Tasks to be done:

1. Use the inbuilt functions and find the minimum, maximum and average amount from the orders
table

2. Create a user-defined function, which will multiply the given number with 10

3. Use the case statement to check if 100 is less than 200, greater than 200 or equal to 2oo and
print the corresponding value

Solutions

1.

SELECT MAX(amount) AS MAX_AMT FROM orders

RESULT

MAX_AMT
200

SELECT MIN(amount) AS MIN_AMT FROM orders

RESULT

MIN_AMT
100

/2

ANITA BALAKRISHNAN EMAIL annkallid@gmail.com MODULE 4 ASSIGNMENT SQL


-2-

SELECT AVG(amount) AS AVERAGE FROM orders

RESULT

AVERAGE
137

(FOR REFERENCE PURPOSE ONLY Orders table details are shown below)

Order_id order_date amount customer_id


1001 2021-10-15 100 1
1002 2021-10-16 150 2
1003 2021-10-17 100 3
1004 2021-10-18 200 4

2.

CREATE FUNCTION MULTIPLY_BY_10(@NUM INT)


RETURNS INT
AS
BEGIN
SET @NUM=@NUM*10
RETURN @NUM
END

PRINT DBO.MULTIPLY_BY_10(20)

SELECT * dbo.multiply(amount) as multi_Amt FROM Orders

3.

DECLARE @input INT


SET @input=100
SELECT
CASE
WHEN @input<200 THEN 'input is less than 200'
WHEN @input>200 THEN 'input is greater than 200'
ELSE 'input is equal to 200'
END as result

RESULT

result
input is less than 200

ANITA BALAKRISHNAN EMAIL annkallid@gmail.com MODULE 4 ASSIGNMENT SQL

You might also like