#Advanced 1: Basic query
/* Syntax
select query list from table name;
Features:
1. The query list can be: fields in the table, constant values, expressions, functions
2. The result of the query is a virtual table
*/
#0. Use the database
USE employees;
#1. Query a single field in the table
SELECT last_name FROM employees;
#2. Query multiple fields in the table
SELECT last_name,salary,email FROM employees;
#3. Query all fields in the table
SELECT * FROM employees;
#4. Query constant value
SELECT 100;
#5. Query expression
SELECT 100*99;
#6. Query function
SELECT VERSION();
#7.起 alias
# Method 1:
SELECT
last_name AS 姓,first_name AS 名
FROM employees;
#法二:
SELECT last_name 姓,first_name 名 FROM employees;
#Case: query salary, the display result is out put;
SELECT salary AS "out put" FROM employees;
#8.去重
#Query all department numbers involved in the employee table
SELECT DISTINCT department_id FROM employees;
#9. The effect of the + sign
/*
select 100+90; If both operands are of numeric type, do an addition operation
select '123'+90; one of them is a character type, trying to convert a character type value into a numeric type
conversion If it succeeds, do the addition operation
select'john'+90; if the conversion fails, the character type is converted to 0
select null+10; if one party is NULL, the result is NULL
*/
#Case: query the employee's name and surname into one field, and Display as name
SELECT
CONCAT(last_name,first_name)
AS
姓名
FROM
employees;
#after class homework
SELECT
CONCAT(`last_name`,',',`phone_number`,',',`job_id`,',',`salary`)
AS
out_put FROM employees;
SELECT
IFNULL(commission_pct,0) AS 奖金率,
commission_pct
FROM
employees;