рдореБрдЦреНрдп рд╕рд╛рдордЧреНрд░реА рдкрд░ рдЬрд╛рдПрдБ

Functions

MySQL functions perform specific operations on data, making queries more efficient and flexible. They are categorized into aggregate, string, date, and mathematical functions.

Common Uses of MySQL Functions

  1. Aggregate Functions: Summarize data (e.g., SUM()).
  2. String Functions: Modify text (e.g., CONCAT()).
  3. Date Functions: Manipulate dates (e.g., NOW()).
  4. Mathematical Functions: Perform calculations (e.g., ROUND()).
  5. JSON Functions: Handle JSON data (e.g., JSON_OBJECT()).

Examples

  1. Aggregate Function
    ┬а

    Explanation: Calculates the average salary of employees.

  2. String Function
    ┬а

    Explanation: Converts customer names to uppercase.

  3. Date Function

    Explanation: Retrieves the current date.

  4. Mathematical Function
    ┬а

    Explanation: Rounds the price to two decimal places.

  5. JSON Function
    ┬а
    SELECT JSON_OBJECT('id', id, 'name', name) AS json_data FROM users;

    Explanation: Converts id and name columns into a JSON object.