remove non ascii whitespaces
This commit is contained in:
parent
598a10bc28
commit
5a6d6c4d13
117 changed files with 1928 additions and 1928 deletions
|
@ -79,7 +79,7 @@ Conditionals like `if` and `match` can be used, while `match` can do more powerf
|
|||
let age = 20;
|
||||
if age > 18 {
|
||||
println!("Adult");
|
||||
} else if age == 18 {
|
||||
} else if age == 18 {
|
||||
println!("Exactly 18");
|
||||
} else {
|
||||
println!("Minor");
|
||||
|
@ -156,7 +156,7 @@ struct Person {
|
|||
|
||||
impl Person {
|
||||
fn new(first_name: &str) -> Self {
|
||||
Self {
|
||||
Self {
|
||||
first_name: first_name.to_string(),
|
||||
age: 0
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ A database most often contains one or more tables. Each table is identified by a
|
|||
Most of the actions you need to perform on a database are done with SQL statements.
|
||||
Example:
|
||||
```sql
|
||||
SELECT * FROM Customers;
|
||||
SELECT * FROM Customers;
|
||||
```
|
||||
|
||||
### Comments
|
||||
|
@ -31,12 +31,12 @@ SELECT * FROM Customers;
|
|||
```
|
||||
|
||||
## SELECT
|
||||
The `SELECT` statement is used to select data from a database.
|
||||
The `SELECT` statement is used to select data from a database.
|
||||
|
||||
Select:
|
||||
```sql
|
||||
SELECT column1, column2, ...
|
||||
FROM table_name;
|
||||
SELECT column1, column2, ...
|
||||
FROM table_name;
|
||||
```
|
||||
|
||||
Select all:
|
||||
|
@ -45,7 +45,7 @@ SELECT * FROM table
|
|||
```
|
||||
|
||||
### SELECT DISTINC
|
||||
The `SELECT DISTINCT` statement is used to return only distinct (different) values.
|
||||
The `SELECT DISTINCT` statement is used to return only distinct (different) values.
|
||||
|
||||
```sql
|
||||
SELECT DISTINCT Country FROM Customers;
|
||||
|
@ -53,7 +53,7 @@ SELECT COUNT(DISTINCT Country) FROM Customers;
|
|||
```
|
||||
|
||||
## WHERE
|
||||
The `WHERE` clause is used to filter records.
|
||||
The `WHERE` clause is used to filter records.
|
||||
|
||||
```sql
|
||||
SELECT column1, column2, ...
|
||||
|
@ -71,7 +71,7 @@ SELECT * FROM Customers
|
|||
WHERE CustomerID=1;
|
||||
```
|
||||
|
||||
The following operators can be used in the `WHERE` clause:
|
||||
The following operators can be used in the `WHERE` clause:
|
||||
|
||||
| Operator | Description |
|
||||
| -------- | ------------------------------------------------------------------------------- |
|
||||
|
@ -80,17 +80,17 @@ The following operators can be used in the `WHERE` clause:
|
|||
| < | Less than |
|
||||
| >= | Greater than or equal |
|
||||
| <= | Less than or equal |
|
||||
| <> | Not equal. **Note:** In some versions of SQL this operator may be written as != |
|
||||
| <> | Not equal. **Note:** In some versions of SQL this operator may be written as != |
|
||||
| BETWEEN | Between a certain range |
|
||||
| LIKE | Search for a pattern |
|
||||
| IN | To specify multiple possible values for a column |
|
||||
|
||||
### LIKE
|
||||
The `LIKE` operator is used in a `WHERE` clause to search for a specified pattern in a column.
|
||||
The `LIKE` operator is used in a `WHERE` clause to search for a specified pattern in a column.
|
||||
|
||||
There are two wildcards often used in conjunction with the `LIKE` operator:
|
||||
- The percent sign `%` represents zero, one, or multiple characters
|
||||
- The underscore sign `_` represents one, single character
|
||||
There are two wildcards often used in conjunction with the `LIKE` operator:
|
||||
- The percent sign `%` represents zero, one, or multiple characters
|
||||
- The underscore sign `_` represents one, single character
|
||||
|
||||
```sql
|
||||
SELECT column1, column2, ...
|
||||
|
@ -99,72 +99,72 @@ WHERE columnN LIKE pattern;
|
|||
```
|
||||
|
||||
#### The _ Wildcard
|
||||
The `_` wildcard represents a single character.
|
||||
It can be any character or number, but each `_` represents one, and only one, character.
|
||||
The `_` wildcard represents a single character.
|
||||
It can be any character or number, but each `_` represents one, and only one, character.
|
||||
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE city LIKE 'L_nd__';
|
||||
SELECT * FROM Customers
|
||||
WHERE city LIKE 'L_nd__';
|
||||
```
|
||||
|
||||
#### The % Wildcard
|
||||
The `%` wildcard represents any number of characters, even zero characters.
|
||||
The `%` wildcard represents any number of characters, even zero characters.
|
||||
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE city LIKE '%L%';
|
||||
SELECT * FROM Customers
|
||||
WHERE city LIKE '%L%';
|
||||
```
|
||||
|
||||
#### Starts With
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerName LIKE 'La%';
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerName LIKE 'La%';
|
||||
```
|
||||
|
||||
#### Ends With
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerName LIKE '%a';
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerName LIKE '%a';
|
||||
```
|
||||
|
||||
#### Contains
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerName LIKE '%or%';
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerName LIKE '%or%';
|
||||
```
|
||||
|
||||
### IN
|
||||
The `IN` operator allows you to specify multiple values in a `WHERE` clause.
|
||||
The `IN` operator allows you to specify multiple values in a `WHERE` clause.
|
||||
|
||||
The `IN` operator is a shorthand for multiple `OR` conditions.
|
||||
The `IN` operator is a shorthand for multiple `OR` conditions.
|
||||
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE Country IN ('Germany', 'France', 'UK');
|
||||
SELECT * FROM Customers
|
||||
WHERE Country IN ('Germany', 'France', 'UK');
|
||||
```
|
||||
|
||||
Subquery:
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders);
|
||||
SELECT * FROM Customers
|
||||
WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders);
|
||||
```
|
||||
|
||||
### BETWEEN
|
||||
The `BETWEEN` operator selects values within a given range. The values can be numbers, text, or dates.
|
||||
The `BETWEEN` operator selects values within a given range. The values can be numbers, text, or dates.
|
||||
|
||||
The `BETWEEN` operator is inclusive: begin and end values are included.
|
||||
The `BETWEEN` operator is inclusive: begin and end values are included.
|
||||
|
||||
```sql
|
||||
SELECT column_name(s)
|
||||
FROM table_name
|
||||
WHERE column_name BETWEEN value1 AND value2;
|
||||
|
||||
SELECT * FROM Orders
|
||||
WHERE OrderDate BETWEEN '1996-07-01' AND '1996-07-31';
|
||||
SELECT * FROM Orders
|
||||
WHERE OrderDate BETWEEN '1996-07-01' AND '1996-07-31';
|
||||
```
|
||||
|
||||
### AND
|
||||
The `WHERE` clause can contain one or many `AND` operators.
|
||||
The `WHERE` clause can contain one or many `AND` operators.
|
||||
|
||||
```sql
|
||||
SELECT *
|
||||
|
@ -173,7 +173,7 @@ WHERE Country = 'Spain' AND CustomerName LIKE 'G%';
|
|||
```
|
||||
|
||||
### OR
|
||||
The `WHERE` clause can contain one or more `OR` operators.
|
||||
The `WHERE` clause can contain one or more `OR` operators.
|
||||
|
||||
```sql
|
||||
SELECT *
|
||||
|
@ -188,20 +188,20 @@ WHERE Country = 'Spain' AND (CustomerName LIKE 'G%' OR CustomerName LIKE 'R%');
|
|||
```
|
||||
|
||||
### NOT
|
||||
The `NOT` operator is used in combination with other operators to give the opposite result, also called the negative result.
|
||||
The `NOT` operator is used in combination with other operators to give the opposite result, also called the negative result.
|
||||
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
WHERE NOT Country = 'Spain';
|
||||
SELECT * FROM Customers
|
||||
WHERE NOT Country = 'Spain';
|
||||
|
||||
SELECT * FROM Customers
|
||||
WHERE City NOT IN ('Paris', 'London');
|
||||
SELECT * FROM Customers
|
||||
WHERE City NOT IN ('Paris', 'London');
|
||||
```
|
||||
|
||||
## ORDER BY
|
||||
The `ORDER BY` keyword is used to sort the result-set in ascending or descending order.
|
||||
The `ORDER BY` keyword is used to sort the result-set in ascending or descending order.
|
||||
|
||||
The `ORDER BY` keyword sorts the records in ascending order by default. To sort the records in descending order, use the `DESC` keyword.
|
||||
The `ORDER BY` keyword sorts the records in ascending order by default. To sort the records in descending order, use the `DESC` keyword.
|
||||
|
||||
```sql
|
||||
SELECT column1, column2, ...
|
||||
|
@ -210,7 +210,7 @@ ORDER BY column1, column2, ... ASC|DESC;
|
|||
```
|
||||
|
||||
## INSERT INTO
|
||||
The `INSERT INTO` statement is used to insert new records in a table.
|
||||
The `INSERT INTO` statement is used to insert new records in a table.
|
||||
|
||||
Example:
|
||||
```sql
|
||||
|
@ -228,7 +228,7 @@ VALUES
|
|||
```
|
||||
|
||||
## UPDATE
|
||||
The `UPDATE` statement is used to modify the existing records in a table.
|
||||
The `UPDATE` statement is used to modify the existing records in a table.
|
||||
|
||||
```sql
|
||||
UPDATE table_name
|
||||
|
@ -237,7 +237,7 @@ WHERE condition;
|
|||
```
|
||||
|
||||
## DELETE
|
||||
The `DELETE` statement is used to delete existing records in a table.
|
||||
The `DELETE` statement is used to delete existing records in a table.
|
||||
|
||||
Example:
|
||||
```sql
|
||||
|
@ -251,11 +251,11 @@ DELETE FROM table_name;
|
|||
|
||||
Delete Table:
|
||||
```sql
|
||||
DROP TABLE table_name;
|
||||
DROP TABLE table_name;
|
||||
```
|
||||
|
||||
## LIMIT
|
||||
The `LIMIT` clause is used to specify the number of records to return.
|
||||
The `LIMIT` clause is used to specify the number of records to return.
|
||||
|
||||
```sql
|
||||
SELECT * FROM Customers
|
||||
|
@ -266,7 +266,7 @@ LIMIT 3;
|
|||
SQL aliases are used to give a table, or a column in a table, a temporary name.
|
||||
Aliases are often used to make column names more readable.
|
||||
An alias only exists for the duration of that query.
|
||||
An alias is created with the `AS` keyword.
|
||||
An alias is created with the `AS` keyword.
|
||||
|
||||
```sql
|
||||
SELECT column_name AS alias_name
|
||||
|
@ -274,34 +274,34 @@ FROM table_name;
|
|||
```
|
||||
|
||||
## JOIN
|
||||
A `JOIN` clause is used to combine rows from two or more tables, based on a related column between them.
|
||||
A `JOIN` clause is used to combine rows from two or more tables, based on a related column between them.
|
||||
|
||||
### INNER JOIN
|
||||
The `INNER JOIN` keyword selects records that have matching values in both tables.
|
||||
The `INNER JOIN` keyword selects records that have matching values in both tables.
|
||||
|
||||
```sql
|
||||
SELECT Orders.OrderID, Customers.CustomerName
|
||||
FROM Orders
|
||||
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
|
||||
SELECT Orders.OrderID, Customers.CustomerName
|
||||
FROM Orders
|
||||
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
|
||||
```
|
||||
|
||||
# Database
|
||||
## Create Database
|
||||
The `CREATE DATABASE` statement is used to create a new SQL database.
|
||||
The `CREATE DATABASE` statement is used to create a new SQL database.
|
||||
|
||||
```sql
|
||||
CREATE DATABASE databasename;
|
||||
```
|
||||
|
||||
## Delete Database
|
||||
The `DROP DATABASE` statement is used to drop an existing SQL database.
|
||||
The `DROP DATABASE` statement is used to drop an existing SQL database.
|
||||
|
||||
```sql
|
||||
DROP DATABASE databasename;
|
||||
```
|
||||
|
||||
## Create Table
|
||||
The `CREATE TABLE` statement is used to create a new table in a database.
|
||||
The `CREATE TABLE` statement is used to create a new table in a database.
|
||||
|
||||
```sql
|
||||
CREATE TABLE table_name (
|
||||
|
@ -321,15 +321,15 @@ CREATE TABLE Persons (
|
|||
```
|
||||
|
||||
## Delete Table
|
||||
The `DROP TABLE` statement is used to drop an existing table in a database.
|
||||
The `DROP TABLE` statement is used to drop an existing table in a database.
|
||||
|
||||
```sql
|
||||
DROP TABLE table_name;
|
||||
```
|
||||
|
||||
## Change Table
|
||||
The `ALTER TABLE` statement is used to add, delete, or modify columns in an existing table.
|
||||
The `ALTER TABLE` statement is also used to add and drop various constraints on an existing table.
|
||||
The `ALTER TABLE` statement is used to add, delete, or modify columns in an existing table.
|
||||
The `ALTER TABLE` statement is also used to add and drop various constraints on an existing table.
|
||||
|
||||
Add Column:
|
||||
```sql
|
||||
|
@ -339,8 +339,8 @@ ADD Email varchar(255);
|
|||
|
||||
Drop Column:
|
||||
```sql
|
||||
ALTER TABLE Customers
|
||||
DROP COLUMN Email;
|
||||
ALTER TABLE Customers
|
||||
DROP COLUMN Email;
|
||||
```
|
||||
|
||||
Rename Column:
|
||||
|
@ -356,7 +356,7 @@ ALTER COLUMN DateOfBirth year;
|
|||
```
|
||||
|
||||
## Constraints
|
||||
Constraints can be specified when the table is created with the `CREATE TABLE` statement, or after the table is created with the `ALTER TABLE` statement.
|
||||
Constraints can be specified when the table is created with the `CREATE TABLE` statement, or after the table is created with the `ALTER TABLE` statement.
|
||||
|
||||
```sql
|
||||
CREATE TABLE table_name (
|
||||
|
@ -371,30 +371,30 @@ The following constraints are commonly used in SQL:
|
|||
### NOT NULL
|
||||
By default, a column can hold NULL values.
|
||||
|
||||
The `NOT NULL` constraint enforces a column to NOT accept NULL values.
|
||||
The `NOT NULL` constraint enforces a column to NOT accept NULL values.
|
||||
|
||||
This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field.
|
||||
|
||||
```sql
|
||||
CREATE TABLE Persons (
|
||||
ID int NOT NULL,
|
||||
LastName varchar(255) NOT NULL,
|
||||
FirstName varchar(255) NOT NULL,
|
||||
Age int
|
||||
CREATE TABLE Persons (
|
||||
ID int NOT NULL,
|
||||
LastName varchar(255) NOT NULL,
|
||||
FirstName varchar(255) NOT NULL,
|
||||
Age int
|
||||
);
|
||||
```
|
||||
|
||||
### UNIQUE
|
||||
The `UNIQUE` constraint ensures that all values in a column are different.
|
||||
The `UNIQUE` constraint ensures that all values in a column are different.
|
||||
|
||||
Both the `UNIQUE` and `PRIMARY KEY` constraints provide a guarantee for uniqueness for a column or set of columns.
|
||||
Both the `UNIQUE` and `PRIMARY KEY` constraints provide a guarantee for uniqueness for a column or set of columns.
|
||||
|
||||
A `PRIMARY KEY` constraint automatically has a `UNIQUE` constraint.
|
||||
A `PRIMARY KEY` constraint automatically has a `UNIQUE` constraint.
|
||||
|
||||
However, you can have many `UNIQUE` constraints per table, but only one `PRIMARY KEY` constraint per table.
|
||||
However, you can have many `UNIQUE` constraints per table, but only one `PRIMARY KEY` constraint per table.
|
||||
|
||||
### PRIMARY KEY
|
||||
The `PRIMARY KEY` constraint uniquely identifies each record in a table.
|
||||
The `PRIMARY KEY` constraint uniquely identifies each record in a table.
|
||||
|
||||
Primary keys must contain UNIQUE values, and cannot contain NULL values.
|
||||
|
||||
|
@ -411,9 +411,9 @@ CREATE TABLE Persons (
|
|||
```
|
||||
|
||||
### FOREIGN KEY
|
||||
The `FOREIGN KEY` constraint is used to prevent actions that would destroy links between tables.
|
||||
The `FOREIGN KEY` constraint is used to prevent actions that would destroy links between tables.
|
||||
|
||||
A `FOREIGN KEY` is a field (or collection of fields) in one table, that refers to the `PRIMARY KEY` in another table.
|
||||
A `FOREIGN KEY` is a field (or collection of fields) in one table, that refers to the `PRIMARY KEY` in another table.
|
||||
|
||||
The table with the foreign key is called the child table, and the table with the primary key is called the referenced or parent table.
|
||||
|
||||
|
@ -428,32 +428,32 @@ CREATE TABLE Orders (
|
|||
```
|
||||
|
||||
### CHECK
|
||||
The `CHECK` constraint is used to limit the value range that can be placed in a column.
|
||||
The `CHECK` constraint is used to limit the value range that can be placed in a column.
|
||||
|
||||
If you define a `CHECK` constraint on a column it will allow only certain values for this column.
|
||||
If you define a `CHECK` constraint on a column it will allow only certain values for this column.
|
||||
|
||||
If you define a `CHECK` constraint on a table it can limit the values in certain columns based on values in other columns in the row.
|
||||
If you define a `CHECK` constraint on a table it can limit the values in certain columns based on values in other columns in the row.
|
||||
|
||||
```sql
|
||||
CREATE TABLE Persons (
|
||||
ID int NOT NULL,
|
||||
LastName varchar(255) NOT NULL,
|
||||
FirstName varchar(255),
|
||||
Age int,
|
||||
CHECK (Age>=18)
|
||||
CREATE TABLE Persons (
|
||||
ID int NOT NULL,
|
||||
LastName varchar(255) NOT NULL,
|
||||
FirstName varchar(255),
|
||||
Age int,
|
||||
CHECK (Age>=18)
|
||||
);
|
||||
```
|
||||
|
||||
### DEFAULT
|
||||
The `DEFAULT` constraint is used to set a default value for a column.
|
||||
The `DEFAULT` constraint is used to set a default value for a column.
|
||||
|
||||
The default value will be added to all new records, if no other value is specified.
|
||||
|
||||
```sql
|
||||
CREATE TABLE Orders (
|
||||
ID int NOT NULL,
|
||||
OrderNumber int NOT NULL,
|
||||
OrderDate date DEFAULT GETDATE()
|
||||
CREATE TABLE Orders (
|
||||
ID int NOT NULL,
|
||||
OrderNumber int NOT NULL,
|
||||
OrderDate date DEFAULT GETDATE()
|
||||
);
|
||||
```
|
||||
|
||||
|
@ -463,17 +463,17 @@ Auto-increment allows a unique number to be generated automatically when a new r
|
|||
Often this is the primary key field that we would like to be created automatically every time a new record is inserted.
|
||||
|
||||
```sql
|
||||
CREATE TABLE Persons (
|
||||
Personid int NOT NULL AUTO_INCREMENT,
|
||||
LastName varchar(255) NOT NULL,
|
||||
FirstName varchar(255),
|
||||
Age int,
|
||||
PRIMARY KEY (Personid)
|
||||
CREATE TABLE Persons (
|
||||
Personid int NOT NULL AUTO_INCREMENT,
|
||||
LastName varchar(255) NOT NULL,
|
||||
FirstName varchar(255),
|
||||
Age int,
|
||||
PRIMARY KEY (Personid)
|
||||
);
|
||||
```
|
||||
|
||||
## Create Index
|
||||
The `CREATE INDEX` statement is used to create indexes in tables.
|
||||
The `CREATE INDEX` statement is used to create indexes in tables.
|
||||
|
||||
Indexes are used to retrieve data from the database more quickly than otherwise. The users cannot see the indexes, they are just used to speed up searches/queries.
|
||||
|
||||
|
@ -483,20 +483,20 @@ ON table_name (column1, column2, ...);
|
|||
```
|
||||
|
||||
## Dates
|
||||
**MySQL** comes with the following data types for storing a date or a date/time value in the database:
|
||||
- `DATE` - format YYYY-MM-DD
|
||||
- `DATETIME` - format: YYYY-MM-DD HH:MI:SS
|
||||
- `TIMESTAMP` - format: YYYY-MM-DD HH:MI:SS
|
||||
- `YEAR` - format YYYY or YY
|
||||
**MySQL** comes with the following data types for storing a date or a date/time value in the database:
|
||||
- `DATE` - format YYYY-MM-DD
|
||||
- `DATETIME` - format: YYYY-MM-DD HH:MI:SS
|
||||
- `TIMESTAMP` - format: YYYY-MM-DD HH:MI:SS
|
||||
- `YEAR` - format YYYY or YY
|
||||
|
||||
## Data Types
|
||||
### String
|
||||
| Data type | Description |
|
||||
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| CHAR(size) | A FIXED length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the column length in characters - can be from 0 to 255. Default is 1 |
|
||||
| VARCHAR(size) | A VARIABLE length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the maximum string length in characters - can be from 0 to 65535 |
|
||||
| BINARY(size) | Equal to CHAR(), but stores binary byte strings. The _size_ parameter specifies the column length in bytes. Default is 1 |
|
||||
| VARBINARY(size) | Equal to VARCHAR(), but stores binary byte strings. The _size_ parameter specifies the maximum column length in bytes. |
|
||||
| CHAR(size) | A FIXED length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the column length in characters - can be from 0 to 255. Default is 1 |
|
||||
| VARCHAR(size) | A VARIABLE length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the maximum string length in characters - can be from 0 to 65535 |
|
||||
| BINARY(size) | Equal to CHAR(), but stores binary byte strings. The _size_ parameter specifies the column length in bytes. Default is 1 |
|
||||
| VARBINARY(size) | Equal to VARCHAR(), but stores binary byte strings. The _size_ parameter specifies the maximum column length in bytes. |
|
||||
| TINYBLOB | For BLOBs (Binary Large Objects). Max length: 255 bytes |
|
||||
| TINYTEXT | Holds a string with a maximum length of 255 characters |
|
||||
| TEXT(size) | Holds a string with a maximum length of 65,535 bytes |
|
||||
|
@ -511,21 +511,21 @@ ON table_name (column1, column2, ...);
|
|||
### Numeric
|
||||
| Data type | Description |
|
||||
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| BIT(_size_) | A bit-value type. The number of bits per value is specified in _size_. The _size_ parameter can hold a value from 1 to 64. The default value for _size_ is 1. |
|
||||
| TINYINT(_size_) | A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| BIT(_size_) | A bit-value type. The number of bits per value is specified in _size_. The _size_ parameter can hold a value from 1 to 64. The default value for _size_ is 1. |
|
||||
| TINYINT(_size_) | A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| BOOL | Zero is considered as false, nonzero values are considered as true. |
|
||||
| BOOLEAN | Equal to BOOL |
|
||||
| SMALLINT(_size_) | A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| MEDIUMINT(_size_) | A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to 16777215. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| INT(_size_) | A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| SMALLINT(_size_) | A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| MEDIUMINT(_size_) | A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to 16777215. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| INT(_size_) | A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| INTEGER(_size_) | Equal to INT(size) |
|
||||
| BIGINT(_size_) | A large integer. Signed range is from -9223372036854775808 to 9223372036854775807. Unsigned range is from 0 to 18446744073709551615. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| FLOAT(_size_, _d_) | A floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. This syntax is deprecated in MySQL 8.0.17, and it will be removed in future MySQL versions |
|
||||
| FLOAT(_p_) | A floating point number. MySQL uses the _p_ value to determine whether to use FLOAT or DOUBLE for the resulting data type. If _p_ is from 0 to 24, the data type becomes FLOAT(). If _p_ is from 25 to 53, the data type becomes DOUBLE() |
|
||||
| DOUBLE(_size_, _d_) | A normal-size floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter |
|
||||
| DOUBLE PRECISION(_size_, _d_) | |
|
||||
| DECIMAL(_size_, _d_) | An exact fixed-point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. The maximum number for _size_ is 65. The maximum number for _d_ is 30. The default value for _size_ is 10. The default value for _d_ is 0. |
|
||||
| DEC(_size_, _d_) | Equal to DECIMAL(size,d) |
|
||||
| BIGINT(_size_) | A large integer. Signed range is from -9223372036854775808 to 9223372036854775807. Unsigned range is from 0 to 18446744073709551615. The _size_ parameter specifies the maximum display width (which is 255) |
|
||||
| FLOAT(_size_, _d_) | A floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. This syntax is deprecated in MySQL 8.0.17, and it will be removed in future MySQL versions |
|
||||
| FLOAT(_p_) | A floating point number. MySQL uses the _p_ value to determine whether to use FLOAT or DOUBLE for the resulting data type. If _p_ is from 0 to 24, the data type becomes FLOAT(). If _p_ is from 25 to 53, the data type becomes DOUBLE() |
|
||||
| DOUBLE(_size_, _d_) | A normal-size floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter |
|
||||
| DOUBLE PRECISION(_size_, _d_) | |
|
||||
| DECIMAL(_size_, _d_) | An exact fixed-point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. The maximum number for _size_ is 65. The maximum number for _d_ is 30. The default value for _size_ is 10. The default value for _d_ is 0. |
|
||||
| DEC(_size_, _d_) | Equal to DECIMAL(size,d) |
|
||||
|
||||
### Date & Time
|
||||
| Data type | Description |
|
||||
|
@ -570,7 +570,7 @@ SELECT UPPER("SQL");
|
|||
The `TRIM()` function removes leading and trailing spaces from a string. `LTRIM()` & `RTRIM()` remove leading and trailing spaces from the left or right respectively.
|
||||
|
||||
```sql
|
||||
SELECT TRIM(' SQL ') AS TrimmedString;
|
||||
SELECT TRIM(' SQL ') AS TrimmedString;
|
||||
```
|
||||
|
||||
### SUBSTRING()
|
||||
|
@ -602,7 +602,7 @@ The `REVERSE()` function reverses a string and returns the result.
|
|||
The `REPLACE()` function replaces all occurrences of a substring within a string, with a new substring.
|
||||
|
||||
```sql
|
||||
REPLACE(string, from_string, new_string)
|
||||
REPLACE(string, from_string, new_string)
|
||||
```
|
||||
|
||||
### REPEAT()
|
||||
|
@ -614,50 +614,50 @@ REPEAT(string, number)
|
|||
|
||||
## Numeric Functions
|
||||
### MIN() & MAX()
|
||||
The `MIN()` function returns the smallest value of the selected column.
|
||||
The `MIN()` function returns the smallest value of the selected column.
|
||||
|
||||
The `MAX()` function returns the largest value of the selected column.
|
||||
The `MAX()` function returns the largest value of the selected column.
|
||||
|
||||
```sql
|
||||
SELECT MIN(Price)
|
||||
FROM Products;
|
||||
SELECT MIN(Price)
|
||||
FROM Products;
|
||||
|
||||
SELECT MAX(Price)
|
||||
FROM Products;
|
||||
SELECT MAX(Price)
|
||||
FROM Products;
|
||||
```
|
||||
|
||||
### COUNT()
|
||||
The `COUNT()` function returns the number of rows that matches a specified criterion.
|
||||
The `COUNT()` function returns the number of rows that matches a specified criterion.
|
||||
|
||||
```sql
|
||||
SELECT COUNT(*)
|
||||
FROM Products;
|
||||
SELECT COUNT(*)
|
||||
FROM Products;
|
||||
```
|
||||
|
||||
### SUM()
|
||||
The `SUM()` function returns the total sum of a numeric column.
|
||||
The `SUM()` function returns the total sum of a numeric column.
|
||||
|
||||
Example:
|
||||
```sql
|
||||
SELECT SUM(Quantity) AS total
|
||||
FROM OrderDetails;
|
||||
SELECT SUM(Quantity) AS total
|
||||
FROM OrderDetails;
|
||||
```
|
||||
|
||||
Expressions:
|
||||
```sql
|
||||
SELECT SUM(Quantity * 10)
|
||||
FROM OrderDetails;
|
||||
SELECT SUM(Quantity * 10)
|
||||
FROM OrderDetails;
|
||||
```
|
||||
|
||||
### AVG()
|
||||
The `AVG()` function returns the average value of a numeric column.
|
||||
The `AVG()` function returns the average value of a numeric column.
|
||||
|
||||
```sql
|
||||
SELECT AVG(Price)
|
||||
FROM Products;
|
||||
SELECT AVG(Price)
|
||||
FROM Products;
|
||||
|
||||
SELECT * FROM Products
|
||||
WHERE price > (SELECT AVG(price) FROM Products);
|
||||
SELECT * FROM Products
|
||||
WHERE price > (SELECT AVG(price) FROM Products);
|
||||
```
|
||||
|
||||
## Date Functions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue