MYSQL- basic query

/*
Underlying query   
grammar
    select list of queries from table name;
    Query field list may be variable or expression
*/
USE myemployees;
# Lookup table in a single field
SELECT first_name FROM employees;
# Lookup table in multiple fields
SELECT first_name,last_name FROM employees;
# Lookup tables in all fields
SELECT * FROM employees;
# Query the database version
SELECT VERSION();
# So in the current database query
SELECT DATABASE();  

/ * Alias
Use aliases
SELECT column name AS alias FROM table;
SELECT column names FROM table; 

The role of aliases
1. facilitate understanding
2. In the latter part of the multi-table queries, we can distinguish different tables in different column
*/
SELECT first_name AS 姓 FROM employees;
SELECT last_name AS 名 FROM employees;

/*
Deduplication
Case: All sectors involved in the query table to staff numbers
DISTINCT unique deduplication
*/
SELECT DISTINCT department_id AS department number FROM employees;

/*
"+" Operator only in MySQL
If you are about character or numeric value can be converted to numerical computation to do
If the character will not be converted to the value 0
If null are null
Case: Query employee name and employee name connected to a field 
*/
SELECT 
    CONCAT(first_name,last_name) AS 姓名
FROM 
    employees;
/*
Shows a list of all employees, and the connection between the respective column by a comma, the head of the column OUT_PUT
The IFNULL (determination condition, the processing result)
*/

Guess you like

Origin www.cnblogs.com/bai-boy/p/12190178.html