Welcome to our SQL Functions Reference guide! In this comprehensive tutorial, we'll explore various SQL functions that will help you manipulate and analyze data effectively. This guide is perfect for both beginners and intermediates. 🎯
SQL functions are built-in functions used to perform specific operations on one or more columns of a table. They allow you to perform mathematical, string, date, and logical operations to extract meaningful insights from your data.
SUM()-- Example: Calculate the total sales for a specific period
SELECT SUM(sales) FROM sales_table WHERE period = '2022-Q1';AVG()-- Example: Calculate the average sales for a specific product
SELECT AVG(sales) FROM sales_table WHERE product = 'Product A';MIN() and MAX()-- Example: Find the minimum and maximum prices for a specific product
SELECT MIN(price), MAX(price) FROM products WHERE product = 'Product A';CONCAT()-- Example: Concatenate first name and last name
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM customers;LENGTH()-- Example: Find the length of a string
SELECT LENGTH('Example String') AS string_length;CURRENT_DATE-- Example: Get the current date
SELECT CURRENT_DATE;DATE_FORMAT()-- Example: Format a date in a specific format
SELECT DATE_FORMAT(your_date_column, '%Y-%m-%d') FROM your_table;COUNT()-- Example: Count the number of rows in a table
SELECT COUNT(*) FROM your_table;GROUP BY-- Example: Group sales by product and calculate total sales for each product
SELECT product, SUM(sales) FROM sales_table GROUP BY product;IF()-- Example: Check if a sale is greater than average sale and return 'High Sale'
SELECT IF(sales > AVG(sales), 'High Sale', 'Normal Sale') AS sale_category FROM sales_table;What does the `SUM()` function do in SQL?
By understanding and mastering these SQL functions, you'll be well-equipped to manage and analyze data effectively in your projects. Happy coding! 🚀