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

SQL Functions

The document outlines SQL functions, specifically aggregate functions like COUNT, SUM, AVG, MIN, and MAX, which perform calculations on multiple rows and return summarized results. It also includes various interview questions related to SQL, such as finding age from date of birth, concatenating names, extracting year from dates, and manipulating strings. Examples of SQL queries for each function and question are provided for clarity.

Uploaded by

Wayne Arul
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)
2 views3 pages

SQL Functions

The document outlines SQL functions, specifically aggregate functions like COUNT, SUM, AVG, MIN, and MAX, which perform calculations on multiple rows and return summarized results. It also includes various interview questions related to SQL, such as finding age from date of birth, concatenating names, extracting year from dates, and manipulating strings. Examples of SQL queries for each function and question are provided for clarity.

Uploaded by

Wayne Arul
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/ 3

SQL INTERVIEW BASED CONCEPTS

TOPIC 6 : FUNCTIONS
AGGREGATE FUNCTIONS:
Used to perform calculations on multiple rows of data and return a single
summarized result.
1) Count()
Returns the number of rows that match a given condition

Query:
SELECT COUNT(*) AS TotalRecords FROM Employee;

2) SUM()
Calculates the total sum of a numeric column.

Query:
SELECT SUM(Salary) AS TotalSalary FROM Employee;

3) AVG()
Calculates the average of a numeric column.

Query:
SELECT AVG(Salary) AS AverageSalary FROM Employee;

4) MIN() and MAX()


SELECT MAX(Salary) AS HighestSalary FROM Employee;
SELECT MIN(Salary) AS LowestSalary FROM Employee;

For Date,Time,String functions content ,refer


https://www.geeksforgeeks.org/sql-date-functions/
INTERVIEW QUESTIONS:
1)Find the Age when Date of birth is given

2)Concate firstname and lastname


SELECT CONCAT('John', ' ', 'Doe') AS FullName;

3) How do you extract the year from a date


SELECT EXTRACT(YEAR FROM hire_date) AS hire_year FROM
employees;

4) How do you convert a date to display the month name

5) How do you get the first 3 letters of a name


SELECT SUBSTR(first_name, 1, 3) AS short_name FROM employees;
6) How do you change lowercase names to uppercase in a column
SELECT UPPER(first_name) FROM employees;

7) How do you find records created in the last 7 days


SELECT * FROM users
WHERE created_date >= SYSDATE - 7;

8) How do you get the length of a string


SELECT LENGTH(first_name) FROM employees;

9) How do you replace part of a string


SELECT REPLACE('abc123', '123', 'XYZ') FROM dual;

10) How do you get today's date without the time part
SELECT TRUNC(SYSDATE) AS today_date FROM dual;

You might also like