使用的sql图形软件:SQLyogEnt

使用的数据库:MYSQL5.7

软件地址:

链接:https://pan.baidu.com/s/1lajyXaSnmrO1v5v987NOoA
提取码:i3a4

-------------------------------------------------------------------------------------------------------------------------------------

//创建名为student的数据库

create database student;

//显示数据库是否创建成功

show databases;

//跳转到自己想要做修改的表,指定操作的数据库名为student

use student;

//创建stu表,在创建时指定属性和属性类型,并给于这个属性指定大小

create table stu(id int(4),name varchar(12),age int(10),sex char(2),birthday date);

//显示是否创建表成功

show tables;

//显示数据库stu表的基础信息

desc stu;

//插入数据,varchar和char还有date类型数据使用‘’括起来

insert into stu values(1,'we',11,'n','2019-11-12');

//插入数据有两种方式,一种是指定属性插入和全部属性插入

insert into stu(id,name) values(1,'ju');

insert into stu values(2,'w',11,'n','2019-11-12'),(3,'w',11,'n','2019-11-12'),(4,'w',11,'n','2019-11-12');//连着插入三条数据

//删除student数据库

drop database student;

//删除stu表

drop table stu;

//修改数据库表的信息

update stu set name='jing' where age=11;

update  stu set name='wan',age=18 where id=1;

//删除

delete from stu where id=1;

delete from stu where name='li' and age=18;

//查询

select * from product;//查询所有

select name,price from product;

select name,price+10 from product;//查询所有价格加十后的显示结果

select p.name,p.price from product AS p;//给表起别名,多用于多表查询

select name,price+10 AS "产品的新价格" from product;//给列起别名

select * from product where name="华为电脑001";//查询条件为name="华为电脑001"的全部记录

select *from product where price!=23;//价格不等于23的所有记录

select *from product where price>23 and price<100;//查找价格23到100之间的记录

select * from product where price between 23 and 100;//查找价格23到100之间的记录,包含23

select * from product where price = 23 or price=100;//价格等于23或100的所有记录

select * from product where price in(23,100);//等同于上一句

     //碰到关键字在输入的名称左边加顿号

select distinct type from product;//查找所有type并使用distinct去除重复

select * from product where type is null;//查询出没有分类的所有记录

select * from product where type is not null;//查询出有分类的所有记录

select * from product order by price asc;//按照价格的大小升序排序 

select * from product order by price desc;//按照价格的大小降序排序

//聚合函数

select count(*) AS "总数" from product;//统计有多少条记录,并起个别名(效率低不建议使用)

select count(1) as "总数" from product;//建议这样使用 1 代表只遍历统计下标为1的属性

select sum(price) from product;//查询出所有的价格总和

select max(price) from product;//查询价格最高

select min(price) from product;//查询最低价格

select avg(price) from product;//查询价格的平均值

select avg(price) as '平均值',min(price) as '最小值',max(price) as '最大值' from product;

select avg(price) as '平均值',min(price) as '最小值',max(price) as '最大值' ,count(1) as '总记录数'from product;

模糊查询

select *from product where name like '%电%';//%代表匹配一个或者多个字符,_ 只匹配一个字符

分组操作

select * from product group by type;//根据type进行分组,分组后重复会被去掉

分组后进行过滤,筛选

select * from product group by type having type is not null;

Mysql语句练习记录的更多相关文章

  1. MySQL语句学习记录

    注意,命令行下,每条语句最后都需要加分号. 1.显示所有数据库 SHOW DATABASES 2.使用某数据库 如mysql数据库  use mysql  (sql语句不区分大小写) 3.显示所有表 ...

  2. mysql语句:批量更新多条记录的不同值[转]

    mysql语句:批量更新多条记录的不同值 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 帮助 1 UPDATE mytable SET myfield = 'value' WHERE ...

  3. mysql语句:批量更新多条记录的不同值

    mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 1 UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_va ...

  4. Mysql中 查询慢的 Sql语句的记录查找

    Mysql中 查询慢的 Sql语句的记录查找 慢查询日志 slow_query_log,是用来记录查询比较慢的sql语句,通过查询日志来查找哪条sql语句比较慢,这样可以对比较慢的sql可以进行优化. ...

  5. mysql语句分析

    explain的每个输出行提供一个表的相关信息,并且每个行包括下面的列: 1,id   select识别符.这是select的查询序列号.2,select_type 可以为一下任何一种类型simple ...

  6. MySQL高效获取记录总数

    通常mysql获取查询记录总数我们使用如下语句: SELECT COUNT(*) FROM users WHERE k='avs';  或:SELECT id FROM goods WHERE k=' ...

  7. CentOS7.4安装MySQL踩坑记录

    CentOS7.4安装MySQL踩坑记录 time: 2018.3.19 CentOS7.4安装MySQL时网上的文档虽然多但是不靠谱的也多, 可能因为版本与时间的问题, 所以记录下自己踩坑的过程, ...

  8. MySql基础笔记(二)Mysql语句优化---索引

    Mysql语句优化--索引 一.开始优化前的准备 一)explain语句 当MySql要执行一个查询语句的时候,它首先会对语句进行语法检查,然后生成一个QEP(Query Execution Plan ...

  9. python 全栈开发,Day60(MySQL的前戏,数据库概述,MySQL安装和基本管理,初识MySQL语句)

    一.MySQL的前戏 在学习Mysql之前,我们先来想一下一开始做的登录注册案例,当时我们把用户的信息保存到一个文件中: #用户名 |密码 root|123321 alex|123123 上面文件内容 ...

随机推荐

  1. 【php】PHP制作QQ微信支付宝三合一收款码

    分析 微信扫这个,支付宝扫那个,不仅要加载多张二维码,还要加css/js让它变的好看,作为一个又懒又不想写这些东西的程序猿来说,这可不行. 那能不能把QQ微信支付宝三合一,只需要扫一个收款码就行呢? ...

  2. Hello log4net——做一个实用好用的log4net的demo(转)

    log4net使用指南  (对配置解释比较全面细致,建议做完demo后多看) Log4Net使用详解(周公)——点击打开链接 Log4Net使用详解(续)周公——点击打开链接 点击打开链接 点击打开链 ...

  3. array_fill 填充数组内容

    <?php $a = array_fill(, , 'banana'); $b = array_fill(-, , 'pear'); print_r($a); print_r($b) Array ...

  4. CompletableFuture Quasar 等并发编程

    CompletableFuture基本用法 https://www.cnblogs.com/cjsblog/p/9267163.html Quasar https://blog.csdn.net/ma ...

  5. 静态站点生成器-md-vue-vuepress

    推荐指数:

  6. JS中search查找某些内容,正则表达式|查找分隔的任何项

    JS中可以用indexOf来查找某个字符串里的某些内容的索引,也就是在字符串的位置.如果存在该字符串,会返回该字符串的索引,如果不存在会返回-1,可以通过某些内容的索引是否为-1判断是否存在该字符串. ...

  7. 【git基础】Permission denied (publickey). fatal: Could not read from remote repository

    运行以下git命令的时候出现错误 git push -u origin master error The authenticity of host 'github.com (13.250.177.22 ...

  8. java程序cpu问题排查

    方法一: 转载:http://www.linuxhot.com/java-cpu-used-high.html 1.jps 获取Java进程的PID. 2.jstack pid >> ja ...

  9. Linux入门-1

    操作系统 列举系统:Windows  Mac  Linux  ios  Android   操作系统的定义:操作系统是一个用来协调.管理和控制计算机硬件和软件资源的系统程序,它位于硬件和应用程序之间. ...

  10. php面相对象类中成员

    类中成员 一个类的内部可以有3种代码:属性.方法.类常量它们统称为“类中成员”. 一般属性 属性就是放在一个类中的变量. 定义形式: 形式1: var  $v1 ; //定义不赋值 形式2: var ...