时间:2021-07-01 10:21:17 帮助过:2人阅读
密码:123
进入!
顺便附上今天学习的mysql语句
#建数据库mysql_shiyan CREATE DATABASE mysql_shiyan; #查看数据库 show databases; #使用 mysql_shiyan 数据库 use mysql_shiyan #查看表 show tables; #新建表 CREATE TABLE 表的名字 ( 列名a 数据类型(数据长度), 列名b 数据类型(数据长度), 列名c 数据类型(数据长度) ); 比如: CREATE TABLE employee (id int(10),name char(20),phone int(12)); #插入数据 INSERT INTO 表的名字(列名a,列名b,列名c) VALUES(值1,值2,值3); #查询数据 SELECT * FROM employee; #约束 约束类型: 主键 默认值 唯一 外键 非空 关键字: PRIMARY KEY DEFAULT UNIQUE FOREIGN KEY NOT NUL #直接使用github上复制的源码 source /home/shiyanlou/Desktop/SQL3/MySQL-03-01.sql #select语句 SELECT 要查询的列名 FROM 表名字 WHERE 限制条件;(where可以不填) SELECT name,age FROM employee WHERE age<25 OR age>30; #筛选出age小于25,或age大于30 SELECT name,age FROM employee WHERE age>25 AND age<30; #筛选出age大于25,且age小于30 SELECT name,age,phone,in_dpt FROM employee WHERE in_dpt IN (‘dpt3‘,‘dpt4‘); SELECT name,age,phone,in_dpt FROM employee WHERE in_dpt NOT IN (‘dpt1‘,‘dpt3‘); SELECT name,age,phone FROM employee WHERE phone LIKE ‘1101__‘; #_代表一个 SELECT name,age,phone FROM employee WHERE name LIKE ‘J%‘;# %代表不确定数量 SELECT name,age,salary,phone FROM employee ORDER BY salary DESC; # 对结果排序 asc升 desc降 函数名:COUNT SUM AVG MAX MIN 作用: 计数 求和 求平均值 最大值 最小值 SELECT MAX(salary) AS max_salary,MIN(salary) FROM employee; #子查询 SELECT of_dpt,COUNT(proj_name) AS count_project FROM project WHERE of_dpt IN (SELECT in_dpt FROM employee WHERE name=‘Tom‘); #连接查询 SELECT id,name,people_num FROM employee,department WHERE employee.in_dpt = department.dpt_name ORDER BY id;
windows下mysql配置(第一次)
标签: