Build Your Own AI Assistant Part 1 - Creating the Assistant
116820 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
114678 Views
Control Arduino with Python using Firmata / PyFirmata
87081 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
57314 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
53588 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
52067 Views
LidarBot
Snaszy NAS a 3D printed NAS for Raspberry Pi
Waveshare CM5 boards
The Best Arduino Robot for Beginners
SMARS Lab upgrade with PyCharm
Chicken Nugget Piano
Mini-Rack 3D Design Tutorial
0h 20m
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
90% Percent Complete
By Kevin McAleer, 6 Minutes
In this lesson, we’ll explore SQL functions and expressions that enhance your ability to manipulate, analyze, and transform data. SQL provides a variety of functions, including string, numeric, date, and aggregate functions, that make it easier to handle different types of data efficiently.
SQL functions are built-in commands that perform specific operations on data and return a single result. Functions can be applied to columns in your database to manipulate or calculate values directly within your queries.
Aggregate functions operate on a set of values and return a single result. They are commonly used in conjunction with the GROUP BY clause.
GROUP BY
COUNT
SELECT COUNT(*) FROM users;
SUM
SELECT SUM(salary) FROM employees;
AVG
SELECT AVG(salary) FROM employees;
MIN
SELECT MIN(salary) FROM employees;
MAX
SELECT MAX(salary) FROM employees;
Example: Find the total salary and average salary of employees.
SELECT SUM(salary) AS total_salary, AVG(salary) AS average_salary FROM employees;
String functions allow you to manipulate text data. These functions are useful for formatting, concatenating, and altering strings.
CONCAT
SELECT CONCAT(first_name, ' ', last_name) FROM users;
LENGTH
SELECT LENGTH(name) FROM users;
UPPER
SELECT UPPER(name) FROM users;
LOWER
SELECT LOWER(name) FROM users;
SUBSTRING
SELECT SUBSTRING(name, 1, 3) FROM users;
Example: Retrieve employee names in uppercase and show the length of each name.
SELECT UPPER(name) AS upper_name, LENGTH(name) AS name_length FROM employees;
Numeric functions are used to perform mathematical operations on numeric data.
ROUND
SELECT ROUND(salary, 2) FROM employees;
CEIL
SELECT CEIL(salary) FROM employees;
FLOOR
SELECT FLOOR(salary) FROM employees;
ABS
SELECT ABS(salary - 50000) FROM employees;
Example: Round each employee’s salary to the nearest hundred.
SELECT name, ROUND(salary, -2) AS rounded_salary FROM employees;
Date functions allow you to manipulate and extract information from date and time data.
NOW
SELECT NOW();
CURDATE
SELECT CURDATE();
YEAR
SELECT YEAR(birth_date) FROM users;
MONTH
SELECT MONTH(birth_date) FROM users;
DAY
SELECT DAY(birth_date) FROM users;
DATEDIFF
SELECT DATEDIFF(NOW(), hire_date) FROM employees;
Example: Find the number of days each employee has been with the company, based on their hire date.
SELECT name, DATEDIFF(NOW(), hire_date) AS days_with_company FROM employees;
Expressions in SQL allow you to perform calculations or manipulate data directly in queries.
Example: Calculate a 10% bonus for each employee based on their current salary.
SELECT name, salary, salary * 0.10 AS bonus FROM employees;
Example: Combine first_name and last_name into a single full_name column.
first_name
last_name
full_name
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees;
Example: Calculate each employee’s next anniversary by adding one year to their hire_date.
hire_date
SELECT name, hire_date, DATE_ADD(hire_date, INTERVAL 1 YEAR) AS next_anniversary FROM employees;
Calculate Total and Average Salary: Find the total and average salary of all employees.
String Manipulation: Retrieve the first three letters of each employee’s name and display it in uppercase.
SELECT UPPER(SUBSTRING(name, 1, 3)) AS name_prefix FROM employees;
Round Salaries: Display each employee’s salary rounded to the nearest thousand.
SELECT name, ROUND(salary, -3) AS rounded_salary FROM employees;
Date Difference: Calculate the number of days each employee has worked at the company based on their hire date.
Calculate Bonuses: Calculate a 5% bonus for each employee based on their salary.
SELECT name, salary, salary * 0.05 AS bonus FROM employees;
Here’s a summary of the SQL functions and expressions covered in this lesson:
+
-
*
/
With these SQL functions and expressions, you can perform a wide range of data manipulations directly within your queries. In the next lesson, we’ll wrap up the course with a final project to apply everything you’ve learned.
< Previous Next >