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 [email protected] 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 [email protected] MODULE 4 ASSIGNMENT SQL