--查询基本使用

-- 查询所有列

--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. IIS安装 URL Rewrite Module 2.1

    短地址http://www.iis.net/extensions/URLRewrite 下载页面https://www.iis.net/downloads/microsoft/url-rewrite# ...

  2. Spring Boot 与 Spring MVC到底有什么区别

    前言 Spring 框架就像一个家族,有众多衍生产品例如 boot.security.jpa等等.但他们的基础都是Spring 的 ioc和 aop ioc 提供了依赖注入的容器 aop ,解决了面向 ...

  3. Kafka Eagle 管理平台

    Kafka-Eagle简介 源代码地址:https://github.com/smartloli/kafka-eagle Kafka Eagle是什么 Kafka Eagle是一款用于监控和管理Apa ...

  4. Mybatis【8】-- Mybatis返回List或者Map以及模糊查询怎么搞?

    使用mybatis的时候,经常发现一个需求,我怎么知道自己是不是增加/修改/删除数据成功了? 好像执行sql之后都没有结果的.其实不是的,增删改的sql执行之后都会有一个int类型的返回值,表示的意思 ...

  5. Java源码研究001:关于List的并发修改异常

    这个就是实现一个简单的 ArrayList 的遍历,如果存在一个为"aaa"的值,就添加一个"ccc" package Array; import java.u ...

  6. double 转为long类型

    System.out.println(new Double(234314.999999999).longValue());//234314  System.out.println(new Double ...

  7. sql中筛选条件为空值

    <select id="getEmployeeBasicInformationList" resultType="org.springblade.entity.Al ...

  8. VIM操作快捷键

    i:插入光标前一个字符I:插入行首a:插入光标后一个字符A:插入行末o:向下新开一行,插入行首O:向上新开一行,插入行首M:光标移到中间行L:光标移动到屏幕最后一行行首G:移动到指定行{:按段移动,上 ...

  9. 自动化运维工具-Ansible之5-流程控制

    自动化运维工具-Ansible之5-流程控制 目录 自动化运维工具-Ansible之5-流程控制 playbook条件语句 单条件 多条件 多条件运算 示例 playbook循环语句 with_ite ...

  10. Inno Step软件安装包制作教程

    Inno setup制作软件安装包教程 1,Inno Setup介绍 Inno Setup 是一个免费的安装制作软件,小巧.简便.精美是其最大特点,支持pascal脚本,能快速制作出标准Windows ...