Junior — Middle
What are the main functions most frequently used when working with databases in SQL?
sobes.tech AI
Answer from AI
When working with databases in SQL, the most commonly used functions are:
-
Aggregate functions:
COUNT()— counts the number of rows.SUM()— sums the values of a column.AVG()— calculates the average value.MIN()andMAX()— find the minimum and maximum values.
-
String functions:
CONCAT()— concatenates strings.UPPER()/LOWER()— converts case.SUBSTRING()— extracts a substring.
-
Date and time:
NOW()— current date and time.DATE()— extracts the date from a datetime.
-
Logical and conditional functions:
CASE WHEN— conditional logic.
Example of using an aggregate function:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;
This query counts the number of employees in each department.