--查询基本使用

-- 查询所有列

--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. 很多人不知道的Python 炫技操作:条件语句的写法

    有的人说 Python 是一门 入门容易,但是精通难的语言,这一点我非常赞同. Python 语言里有许多(而且是越来越多)的高级特性,是 Python 发烧友们非常喜欢的.在这些人的眼里,能够写出那 ...

  2. 测试常用sql语句

    一.查询数值型数据:SELECT * FROM tb_name WHERE sum > 100;查询谓词:>,=,<,<>,!=,!>,!<,=>,=& ...

  3. maven项目修改名称后,打包名称和现在名称不一致

    将pom.xm文件中 <artifactId>health</artifactId> 修改成现在项目名称,然后 maven clean ->maven install 如 ...

  4. 大白话Java多线程,小白都能看的懂的哦

    什么是线程 说到线程我们应该先了解下什么是进程,下面这个图片大家应该都比较熟悉吧. 我们看到的这些单独运行的程序就是一个独立的进程,进程之间是相互独立存在的.我们上面图中的360浏览器.百度云盘等等都 ...

  5. hashmap简单实现

    p.p1 { margin: 0; font: 11px Monaco } p.p2 { margin: 0; font: 11px Monaco; min-height: 15px } p.p3 { ...

  6. 关于HashSet

    HashSet存储数据原理: 当HashSet调用add方法时,有返回值,返回值是boolean类型,表示是否添加成功(如果对象不存在,则添加成功,否则添加失败) 但是,添加的过程并不是一个个去遍历去 ...

  7. JAVA Executor(线程池)框架

    一.Executor概述 为更好控制线程,jdk提供一套线程管理框架Executor,帮助开发人员有效地进行线程控制.它们都位于java.util.concurrent包中,是jdk并发包的核心.其中 ...

  8. reactor模式前序:传统IO的WEB服务器设计

    先看一段经典的WEB JAVA服务器设计 JAVA代码为(伪代码) 1 ServerSocket serverSocket = ...; 2 serverSocket.bind(8899); 3 4 ...

  9. select机制

    select机制 函数作用: 在一段时间指定的时间内,监听用户感兴趣的文件描述符上可读.可写和异常事件. 函数原型: #include <sys/time.h> #include < ...

  10. FAAS -- Serverless

    FAAS概念,无服务器运算,功能即服务,function-as-a-service 初创企业-大型企业.民间组织-政府机构 ===>>>> 上云 云计算第三代技术 -- Ser ...