mysql统计age大于20的数_数据库命令记录

本文详细记录了如何使用MySQL进行数据库操作,包括查看数据库、选择表、筛选数据等。特别强调了如何根据age筛选大于20的记录,涉及where、order by、limit等关键字的使用,以及统计、更新、删除和创建表的操作。
摘要由CSDN通过智能技术生成

好记性不如烂笔头,每次看了忘,忘了看,这次做一个记录!

查看存在的数据库

mysql > show databases;

转到自己需要查看的数据库

mysql > use 数据库名;

查看数据库中的表

mysql >show tables;

显示表列

mysql >show columns from 表名;

从example表中,检索名为id的列(输出结果的顺序是杂乱无章的)

mysql >select id from example;

从example表中,检索名为id的列,title的列,time的列

mysql >select id , title ,time from example;

time这一列的日期很多都是重复的,现在只需要每个日期返回一次,列名前加关键字distinct

mysql >select distinct time from example;

限制输出五行,限制加关键字:limit 数字 (显示的结果是select的基础上限制的,select返回的是无序的,第一行是0)

mysql >select id from example limit 5;

限制输出的从XX到XX行,如,限制输出搜索结果的第2到8行

mysql >select id from example limit 2,8;

排序输出关键字:order by 列名,列名,列名(前边的检索结果将会按照by后边的列名排序输出 )默认升序

mysql >select id from example order by id; #按照id排序输出

mysql >select id from example order by time;#按照time排序输出

mysql >select id , title ,time from example order by id , title ;

#检索三列,按照前两列结果排序,先按照id排序,然后按照tilte排序

降序排列,关键字:desc ,想降序哪个字段就写在那个字段后边

mysql >select id , title ,time from example order by id desc, title ;

#搜索结果按照id降序排序,降序对title无效

过滤条件搜索,加关键字where。

如果同时使用order by和where,order by 在where的后边

where =" 字符串" ,字符串不区分大小写

#搜索id = 18的有关字段

mysql >select id , title ,time from example where id = 18;

#可以用表中任意的字段通过where字段顾虑

mysql >select id , title ,time from example where name = "hahahha"

#id为1到20之间的数据

mysql >select id , title ,time from example where id between 1 and 20;

#返回time为空的

mysql >select id , title ,time from example where time IS NULL;

58bb22c7079d

where

and操作符 /or操作符

and操作符的优先级大于or,因此,设置条件时最好加括号

每额外添加一条过滤语句就增加一个and或者or

#id小于18 且 time等于time = "2019-01-01"的数据

mysql >select id , title ,time from example where id < 18 and time = "2019-01-01";

#id小于18 或者 time等于time = "2019-01-01"的数据

mysql >select id , title ,time from example where id < 18 or time = "2019-01-01";

in操作符

in (限定,限定,限定),就是限定过滤的条件范围,范围就在in后边的括号里

比如:

“where id in(1001,1002) 等价于:where id = 1001 and id =1002

#输出id为1,2,3的数据

mysql >select id , title ,time from example where id in (1,2,3);

not操作符 匹配除了后边的条件的

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值