Introduction
Built-in functions help you quickly do common tasks in databases without writing long code. They save time and make your queries easier to read.
Built-in functions help you quickly do common tasks in databases without writing long code. They save time and make your queries easier to read.
SELECT function_name(column_name) FROM table_name;
function_name with the built-in function you want to use, like SUM, COUNT, or UPPER.SELECT part of your query to get results based on your data.employees table.SELECT COUNT(*) FROM employees;
SELECT UPPER(name) FROM customers;
staff table.SELECT AVG(salary) FROM staff;
This query counts how many orders are in the orders table and finds the most recent order date.
SELECT COUNT(*) AS total_orders, MAX(order_date) AS last_order FROM orders;
Built-in functions are ready to use and tested, so they work fast and correctly.
Using them makes your queries shorter and easier to understand.
Remember that some functions work only with certain data types, like numbers or dates.
Built-in functions save time by doing common tasks for you.
They make your database queries simpler and clearer.
Use them to count, calculate, change text, and work with dates easily.
COUNT(), SUM(), and UPPER() are examples of these functions.name to uppercase in SQL?UPPER().SELECT UPPER(column) FROM table;. Other options are not standard SQL functions.sales with a column amount, what will this query return?SELECT COUNT(amount), SUM(amount) FROM sales WHERE amount > 100;
amount > 100, so only those rows are counted and summed.COUNT(amount) counts rows with non-null amounts > 100, and SUM(amount) adds those amounts.SELECT SUM(amount FROM sales;
SUM() requires parentheses enclosing the column name.amount, causing a syntax error.Options:
A) SELECT AVG(amount) FROM sales WHERE sale_date > CURRENT_DATE - INTERVAL '30' DAY;
B) SELECT AVG(amount) FROM sales WHERE sale_date > DATE_SUB(CURRENT_DATE, 30);
C) SELECT AVG(amount) FROM sales WHERE sale_date > CURRENT_DATE - 30;
D) SELECT AVG(amount) FROM sales WHERE sale_date > NOW() - INTERVAL 30 DAY;
CURRENT_DATE - INTERVAL '30' DAY to get the date 30 days ago.DATE_SUB but missing interval unit. SELECT AVG(amount) FROM sales WHERE sale_date > CURRENT_DATE - 30; subtracts integer directly, invalid. SELECT AVG(amount) FROM sales WHERE sale_date > NOW() - INTERVAL 30 DAY; uses NOW() with interval but missing quotes around 30.Pass the test and this pattern moves unknown