0% found this document useful (0 votes)
5 views3 pages

SQL Functions

The document provides a series of SQL queries demonstrating various functions such as ROUND, MOD, LENGTH, LEFT, TRIM, MIN, AVG, COUNT, MONTHNAME, DAYNAME, INSTR, UPPER, and SUBSTR. Each query is accompanied by a brief explanation of its purpose and expected output. Additionally, it includes function explanations with examples to illustrate their usage in SQL.

Uploaded by

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

SQL Functions

The document provides a series of SQL queries demonstrating various functions such as ROUND, MOD, LENGTH, LEFT, TRIM, MIN, AVG, COUNT, MONTHNAME, DAYNAME, INSTR, UPPER, and SUBSTR. Each query is accompanied by a brief explanation of its purpose and expected output. Additionally, it includes function explanations with examples to illustrate their usage in SQL.

Uploaded by

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

SQL Queries

1. Round the value of pi (3.14159) to two decimal places:

SELECT ROUND(3.14159, 2);

2. Calculate the remainder when 125 is divided by 8:

SELECT MOD(125, 8);

3. Display the number of characters in the word 'New Delhi':

SELECT LENGTH('New Delhi');

4. Display the first 5 characters from the word 'Informatics Practices':

SELECT LEFT('Informatics Practices', 5);

5. Display details from email column in the Students table, after removing any
leading and trailing spaces:

SELECT TRIM(email) FROM Students;

6. Display the minimum price from the price column in the Products table:

SELECT MIN(price) FROM Products;

7. Display the first four characters of the order_id column in the Orders table:

SELECT LEFT(order_id, 4) FROM Orders;

8. Display the data from the email column in the Customers table, after eliminating
any leading and trailing spaces:

SELECT TRIM(email) FROM Customers;

9. Display the average value in the rating column in the Reviews table:

SELECT AVG(rating) FROM Reviews;

10.Determine the count of rows in the Transactions table:

SELECT COUNT(*) FROM Transactions;

11.Round the value of 7.89234 to three decimal places:

SELECT ROUND(7.89234, 3);

13.Calculate the remainder when 320 is divided by 15:

SELECT MOD(320, 15);


14.Display the number of characters in the word 'Electronics':

SELECT LENGTH('Electronics');

15.Display the first 7 characters from the word 'Information Technology':

SELECT LEFT('Information Technology', 7);

16.Display details from the address column in the Employees table after removing any
leading and trailing spaces:

SELECT TRIM(address) FROM Employees;

17.To display the name of the month for the current date:

SELECT MONTHNAME(CURDATE());

18.To display the weekday name for the current date:

SELECT DAYNAME(CURDATE());

19.To display the position of the first occurrence of "ka" in "karnataka":

SELECT INSTR('karnataka', 'ka');

20.To display the string in upper case 'Python Program':

SELECT UPPER('Python Program');

21.To compute the remainder of numerator 117 and denominator 17:

SELECT MOD(117, 17);

Function Explanations with Examples

1. LEFT() – Returns the leftmost characters from a string.


SELECT LEFT('Database', 4);
-- Output: 'Data'

2. INSTR() – Returns the position of the first occurrence of a substring.


SELECT INSTR('Technology', 'log');
-- Output: 6

3. SUBSTR() (or SUBSTRING()) – Extracts part of a string.


SELECT SUBSTR('Programming', 4, 5);
-- Output: 'gramm'
4. MONTHNAME() – Returns the full name of the month from a date.
SELECT MONTHNAME('2025-04-16');
-- Output: 'April'

5. MOD() – Returns the remainder of a division.


SELECT MOD(29, 5);
-- Output: 4
6.MID() function in MySQL is used to extract a substring from
a string, similar to SUBSTRING().

SELECT MID('Informatics', 2, 5);


Output: 'nform'

You might also like