select 查询列表 from 表名;
SELECT last_name FROM employees;
SELECT last_name,salary,email FROM employees;
SELECT 字段1,字段2,...,字段n FROM employees;
SELECT * FROM employees;
着重号“`字段名`”用于区分字段名与关键字,避免混淆。
SELECT 100; SELECT 'john';
SELECT 100%98;
SELECT VERSION();
SELECT 100%98 AS 结果; SELECT last_name AS 姓,first_name AS 名 FROM employees;
SELECT last_name 姓,first_name 名 FROM employees;
如果别名中含有关键字,可以加上双引号。
SELECT salary AS "out put" FROM employees;
SELECT DISTINCT department_id FROM employees;
mysql中的+号只有一个功能:运算符
如果两个操作数都为数值型,则做加法运算,如SELECT 100+90;
只要其中一方为字符型,试图将字符型转换为数值型,如果转换成功,则继续做加法运算,如SELECT '123'+90;
;如果转换失败,则将字符型转换为0,如SELECT 'john'+90;
只要其中一方为null,则结果肯定为null,如SELECT null+10;
使用CONCAT函数
SELECT CONCAT(last_name,first_name) AS 姓名 FROM employees;