MYSQL Functions: All You Need to Know - CNDRO.LLC
3164
post-template-default,single,single-post,postid-3164,single-format-standard,wp-custom-logo,theme-bridge,bridge-core-2.9.4,woocommerce-no-js,tribe-no-js,ehf-template-bridge,ehf-stylesheet-bridge-child,qode-page-transition-enabled,ajax_fade,page_not_loaded,,qode-title-hidden,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,columns-4,qode-child-theme-ver-1.0.0,qode-theme-ver-27.8,qode-theme-bridge,qode_header_in_grid,wpb-js-composer js-comp-ver-6.7.0,vc_responsive,elementor-default,elementor-kit-2634

MYSQL Functions: All You Need to Know

Types of functions

  • Numeric functions — These are functions that operate on numeric data types
  • Strings functions — These are functions that operate on string data types
  • Aggregate functions — These are functions that operate on all different data types and produce summarized result sets.
  • Date functions — They are functions that operate on date data types.

Numeric functions

Strings Functions

1 mysql> SELECT CONCAT('My', 'S', 'QL');
2 +---------------------------------------------------------+
3 | CONCAT('My', 'S', 'QL') |
4 +---------------------------------------------------------+
5 | MySQL |
6 +---------------------------------------------------------+
7 1 row in set (0.00 sec)

 

1 mysql> SELECT CHAR_LENGTH("text");
2 +---------------------------------------------------------+
3 | CHAR_LENGTH("text") |
4 +---------------------------------------------------------+
5 | 4 |
6 +---------------------------------------------------------+
7 1 row in set (0.00 sec)

 

Aggregate functions

1 +-----------+----------------------------+--------------+-----+
2 | groc_code | groc_name | groc_price
3 +-----------+----------------------------+--------------+-----+
4 | 1 |Little Steps Growing up Milk| 7.75
5 | 2 | Sacla Basil Pesto 190g | 2.50
6 | 3 | Golden Caster Sugar 500g | 1.30
7 | 4 | Higgidy Spinach & Pine Nut | 4.00
8 | 5 | Heinz Salad Cream 605g | 2.50

 

1 mysql> SELECT AVG(groc_price) AS price_ag FROM groceries;
2 +----------+
3 | price_ag |
4 +----------+
5 | 3.61 |
6 +----------+
7 1 row in set (0.00 sec)

 

Date functions

1 mysql> SELECT CURDATE(); 
2        -> '2022-04-21' 
3 mysql> SELECT CURDATE() + 0; 
4        -> 20220421

 

DATE_ADD

1 mysql> SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY); 
2        -> '2008-02-02' 
3 mysql> SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY); 
4        -> '2008-02-02'

 

No Comments

Post A Comment