数据库MYSQL基础知识框架
2022-10-27 21:44:27 0 举报
AI智能生成
数据库MYSQL基础知识框架
作者其他创作
大纲/内容
mysql基础
查询
例:端口: 3306 tasklist | find ;quot;mysqld;quot; netstat -an |find ;quot;3306
登录
;mysql -u root -p;注意:环境变量的设置
基础命令
show databases; select database(); use test; show tables; select * from goods;
数据库
表
表的创建
数据类型: 数字 int 字符 char varchar 日期 date 表结构创建语法: create table 表( 列 数据类型, 列 数据类型 );
表结构的删除
;语法:drop table 表;
数据操作
新增
语法:insert into 表 values 值; 语法:insert into 表(列1,列2...) values(值1,值2...);
修改
语法:update 表 set 列=值 where 条件;
删除
语法:delete from 表 where 条件; 语法:truncate table 表;
查询
语法:select 列 from 表 where 条件;
ECShop
查询可以查询指定的行,指定的列,指定行的列语法:select 列 from 表 where 条件;*是代表表中所有的列名
查询ecs_goods表中所有数据select * from ecs_goods;查询ecs_goods表中商品名称为KD876的所有数据select * from ecs_goods where goods_name=;apos;KD876;apos;;查询ecs_goods表中所有的商品名称select goods_name from ecs_goods;查询ecs_goods表中商品名称P806的商品名称和本店售价select goods_name,shop_price from ecs_goods where goods_name=;apos;P806;apos;
where查询
比较运算
1.比较运算 ;gt; 大于 ;lt; 小于 = 等于 ;gt;= 大于等于 ;lt;= 小于等于 != 不等于 不等于
例子:查询ecs_goods表中本店售价高于2000的所有商品信息 select * from ecs_goods where shop_price;gt;2000; 例子:查询ecs_goods表中商品名称不是KD876的所有商品信息 select * from ecs_goods where goods_name;apos;KD876;apos;;
关系运算
关系运算 and 同时满足条件 or 满足一个条件即可 not 不满足条件
例子:查询ecs_goods表中本店售价范围2000和3000之间的所有商品名称 select goods_name from ecs_goods where shop_price;gt;=2000 and shop_price;lt;=3000; 例子:查询商品名称是KD876或者诺基亚的所有信息 select * from ecs_goods where goods_name=;apos;KD876;apos; or goods_name=;apos;诺基亚;apos;;
区间
between ...and ... 注意:小在前,大在后,包括两个端点
例子:查询ecs_goods表中本店售价范围2000和3000之间的所有商品名称 select * from ecs_goods where shop_price between 2000 and 3000;
模糊查询
当信息不完整时候使用模糊查询,多数是和字符类型一起使用like_ 一个字符% 任意个字符
查询ecs_goods表中商品名称诺基亚开头的所有商品信息select * from ecs_goods where goods_name like ;apos;诺基亚%;apos;;查询ecs_goods表中商品名称6结尾的说有商品名称select goods_name from ecs_goods where goods_name like ;apos;%6;apos;;查询ecs_goods表中商品名称是6个字符的所有信息select * from ecs_goods where goods_name like ;apos;______;apos;;
空值查询
null没有任何数据类型,没有任何值,不能用于比较和运算查询时候使用is null或者is not null
例子:查询ecs_goods表中suppliers_id不为空的所有信息 select * from ecs_goods where suppliers_id is not null;
in查询
在...里面...或的关系例子:查询商品名称是KD876或者诺基亚的所有信息select * from ecs_goods where goods_name in(;apos;KD876;apos;,;apos;诺基亚;apos;);
补充
round() 小数点后保留几位upper() 大写lower() 小写select lower(goods_name),goods_namefrom ecs_goods;avg() 平均
select avg(shop_price),round(avg(shop_price),2) from ecs_goods;
0 条评论
下一页