--查询基本使用

-- 查询所有列

--select * from 表名
select * from students;
 

--一定条件查询

select * from students where name='小李飞刀';
select * from students where id>3;
 
 

-- 查询制定列

select name, gender from students;
 

-- 可以使用as制定列或表制定别名;

select name as 姓名, gender as 性别 from students;
 

--字段的顺序

select id as 序号, gender as 性别, name as 姓名 from students;

--创建学生表

create table students (
id int unsigned not null auto_increment primary key,
name varchar(20) default '',
age tinyint unsigned default 0,
high decimal(5,2),
gender enum('男', '女', '中性', '保密') default '保密',
cls_id int unsigned default 0,
is_delete bit default 0
);
 

--创建班级表

create table classes(
id int unsigned auto_increment primary key not null,
name varchar(20) not null
);

--往students表里插入数据

insert into students values
(0,'小明',18,180.00,2,1,0),
(0,'小月月',19,180.00,2,2,0),
(0,'布莱恩特',28,185.00,1,1,0),
(0,'刘德华',58,175.00,1,2,0),
(0,'黄蓉',108,160.00,2,1,0),
(0,'凤姐',44,150.00,4,2,1),
(0,'李白',52,170.00,2,1,1),
(0,'周杰伦儿',34,null,1,1,0),
(0,'程坤',44,181.00,1,2,0),
(0,'金镖十三郎',55,166.00,2,2,0),
(0,'刘亦菲',29,162.00,3,3,0),
(0,'金星',45,180.00,2,4,0),
(0,'静香',18,170.00,1,4,0),
(0,'项羽',22,167.00,2,5,0),
(0,'周杰',33,178.00,1,1,0);

--向classes表里插入数据

insert into classes values (0, 'python_01期'),(0, 'python_02期');
 

--查询

-- 查询所有字段

select * from students;
select * from classes;
 

-- 查询制定的字段

select name, age from students;
 

-- 使用as给字段起别名

select name as 姓名, age as 年龄 from students;
 

-- 通过表名字查询

select students.name, students.age from students;
 

-- 给表起别名查询

select s.name, s.age from students as s;
 

--消除重复行

-- distinct
select distinct gender from students;
 
 

--条件查询

--比较运算符

-- 查询年纪大于18岁的信息

select * from students where age > 18;
select id, name, gender from students where age > 18;
 

--18岁到28岁之间(and)

select * from students where age>18 and age<28;
 

--在18岁以上或者身高180以上的人(or)

select * from students where age>18 or high>=180;
 

-- 模糊查询

-- like

-- % 替代1个或者多个甚至是没有

select * from students where name like '小%';
 

-- 查询姓名中有‘小’的所有名字

select * from students where name like '%小%';
 
 

-- 查询有两个字的名字

select * from students where name like '__';
 

-- 查询至少有2个字的名字

select * from students where name like '__%';
 

-- rlike 正则

-- 查询以周开始的名字

select * from students where name rlike '^周.*';
select * from students where name rlike '^周.*儿$';
 

--范围查询

-- in (1,3,8)表示在一个非连续的范围内

-- 查询 年纪为18,34的人

select * from students where age=18 or age=34;
 
 
select * from students where age=18 or age=34 or age=12;
select * from students where age in (12,18,34);
 
 

--查询 年龄在17岁到34岁之间的信息

select * from students where age between 18 and 34;--(不包含34岁)
 
 

--查询 年纪不在18到34岁的信息

select * from students where age not between 18 and 34;
 

-- 空判断

-- 判断is null
-- 查询身高为空的信息
select * from students where high is null;
 
-- 判断非空is not null
select * from students where high is not null;
select * from students order by age asc;   
  asc从小到大排序
 desc从小到大
 
 

MariaDB(selec的使用)的更多相关文章

  1. Docker笔记一:基于Docker容器构建并运行 nginx + php + mysql ( mariadb ) 服务环境

    首先为什么要自己编写Dockerfile来构建 nginx.php.mariadb这三个镜像呢?一是希望更深入了解Dockerfile的使用,也就能初步了解docker镜像是如何被构建的:二是希望将来 ...

  2. 续 CentOS7(mini) 运行MVC5 + Mariadb

    上一篇,介绍了在CentOS7上使用mono官方二进制安装包快速安装mono环境 并且成功运行了一个Owin自宿主应用(Booker) 由于Owin自宿主应用不需要System.Web的支持,所以可以 ...

  3. 读书笔记--SQL必知必会--常用MySQL(MariaDB)命令

    DBMS信息 显示DBMS的版本 select version(); 显示DBMS状态 status; 显示DBMS资源状态 show status; 显示DBMS支持的权限 show privile ...

  4. 从MySQL 5.5迁移到Mariadb 10.1.14

    从MySQL 5.5迁移到Mariadb 10.1.14 迁移计划如下: 1.备份MySQL 5.5的数据库,对指定库进行备份. 2.还原到Mariadb,然后建立复制. 3.然后就可以愿意啥时候切换 ...

  5. mariadb数据库忘记密码如何找回

    1.systemctl stop mariadb ==>停止mariadb数据库 2.mysqld_safe --skip-grant-tables & ==>进入单机模式 3.m ...

  6. CentOS 7 x64下Apache+MySQL(Mariadb)+PHP56的安装

    每次搭建新服务器,都要来来回回把这些包再装一下,来来回回搞了不下20遍了吧,原来都是凭经验,配置过程中重复入坑是难免的,故写此文做个备忘.虽然有像xampp这样的集成包,但是在生产环境的Linux发行 ...

  7. Ubuntu 16.04 LAMP server 指南 - 配置 Apache2.4,PHP7,和MariaDB(而不是MySQL)

    翻译自:https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/ 昨天在虚 ...

  8. CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置

    1.安装MariaDB 安装命令 yum -y install mariadb mariadb-server 安装完成MariaDB,首先启动MariaDB,两条命令都可以 systemctl sta ...

  9. MySQL/MariaDB/PerconaDB-提权条件竞争漏洞

    背景 2016年11月01日,国外安全研究员Dawid Golunski在 MySQl, MariaDB 和 PerconaDB 数据库中发现条件竞争漏洞,该漏洞允许本地用户使用低权限(CREATE/ ...

随机推荐

  1. 持久层之 MyBatis: 第一篇:快速入门

    MyBatis入门到精通 JDBC回顾 1.1.认识MyBatis 1.1.使用IDEA创建maven工程 1.2.引入mysql依赖包 1.3.准备数据 1.4 使用JDBC手写MyBatis框架 ...

  2. Thymeleaf是个什么东东?

    Thymeleaf是面向Web和独立环境的现代服务器端Java模板引擎,能够处理HTML,XML,JavaScript,CSS甚至纯文本. Thymeleaf的主要目标是提供一个优雅和高度可维护的创建 ...

  3. 【程序包管理】Linux程序包管理之rpm安装总结

    rpm简介 rpm( Red Hat Package Manager )是一个开放的软件包管理系统.它工作于Red Hat Linux及其他Linux系统,成为Linux中公认的软件包管理标准. rp ...

  4. 如何用tep完成增删改查接口自动化

    tep的设计理念是让人人都可以用Python写自动化,本文就来介绍如何用tep完成增删改查接口自动化. 环境变量 编辑fixtures/fixture_admin.py: "qa" ...

  5. docker 使用笔记

    docker 使用笔记 1. 与宿主机之间拷贝文件 docker cp test.html 99f952ac05e6cd879f14aa6c9d0db02aaf498634edc4f6cdc9953c ...

  6. MyBatis-Plus 多表联查+分页

    在写东西的过程中,多表联查和分页功能必不可少.当然,crud也很重要 但是又不想写代码和xml. 通过苦苦的查找.发现MyBatis-Plus一款国产的框架.优化了许多操作 本次主要记录一下,多表联查 ...

  7. 异步技巧之CompletableFuture

    摘自--https://juejin.im/post/5b4622df5188251ac9766f47 异步技巧之CompletableFuture 1.Future接口 1.1 什么是Future? ...

  8. Redis的批量操作是什么?怎么实现的延时队列?以及订阅模式、LRU。

    前言 这次的内容是我自己为了总结Redis知识而扩充的,上一篇其实已经总结了几点知识了,但是Redis的强大,以及适用范围之广可不是单单一篇博文就能总结清的.所以这次准备继续总结,因为第一个问题,Re ...

  9. RPC框架从0到10

    RPC(Remote Procedure Call) 从单机走向分布式,产生了很多分布式的通信方式 最古老也是最有效,并且永不过时的,TCP/UDP的二进制传输,事实上所有的通信方式归根结底都是TCP ...

  10. NAT模式/路由模式/全路由模式 (转)

    route全路由NAT NAT模式.此模式下,由局域网向广域网发送的数据包默认经过NAT转换,但路由器对所有源地址与局域网接口不在同一网段的数据包均不进行处理.例如,路由器LAN口IP设置为192.1 ...