//注:只有管理员身份运行的命令行才可以执行mysql相应的指令
net stop mysql0815
//0815是一个(示例)端口号,写你自己定义的端口号即可
net start mysql0815
mysql -h localhost -P 3306 -u root -p(mima)
//-h是host,-P是端口号,-u是用户名(默认root),-p是密码
//-h和-p和-u后的空格可有可无,-p后不可加空格,除非你的密码里有空格
//密码可输入在-p后显式输入,亦可以输入至-p时直接enter,可隐式输入
//-h localhost -P 3306可省略,即mysql -u root -p(mima)
exit
/*
语法:
select 查询列表 from 表名;
类似于:System.out.println(打印东西);
特点:
1、查询列表可以是:表中的字段、常量值、表达式、函数
2、查询的结果是一个虚拟的表格
*/
//建议开篇使用这个命令
USE myemployees;
SELECT last_name FROM employees;
SELECT last_name,salary,email FROM employees;
方式一:
SELECT
employee_id,
first_name,
last_name,
phone_number,
last_name,
job_id,
phone_number,
job_id,
salary,
commission_pct,
manager_id,
department_id,
hiredate 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;
/*
java中的+号:
①运算符,两个操作数都为数值型
②连接符,只要有一个操作数为字符串
mysql中的+号:
仅仅只有一个功能:运算符
两个操作数都为数值型,则做加法运算
select 100+90;//190
只要其中一方为字符型,试图将字符型数值转换成数值型
如果转换成功,则继续做加法运算
select '123'+90;//213
如果转换失败,则将字符型数值转换成0
select 'john'+90;
只要其中一方为null,则结果肯定为null
select null+10;//(NULL)
SELECT "NULL" + "name";//0
SELECT NULL + "name";//(NULL)
*/
SELECT CONCAT('a','b','c') AS 结果;
SELECT CONCAT(last_name,first_name) AS 姓名 FROM employees;
SELECT last_name , job_id , salary AS sal FROM employees;
SELECT * FROM employees;
SELECT employee_id , last_name, salary * 12 AS "ANNUAL SALARY" FROM employees;
//这个已改正,原来的错误是中文的单引号和双引号的误用
DESC departments;
SELECT * FROM departments
;
SELECT DISTINCT job_id FROM employees;
SELECT
IFNULL(commission_pct,0) AS 奖金率,
commission_pct
FROM
employees;
SELECT CONCAT(first_name
,',',last_name
,',',job_id
,',',IFNULL(commission_pct,0)) AS out_put
FROM
employees;