--查询基本使用

-- 查询所有列

--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:值得学习的二十个技巧

    本文为大家介绍20个值得记住的 Python 技巧,可以提升您编程技巧, 并为您节省大量时间. 在平常编程过程中,以下技巧大多非常有用. 1 字符串反转 使用切片反转字符串. str1="q ...

  2. python绘制美丽花朵

    from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import Line ...

  3. 浅析Python闭包

    1.什么是闭包 在介绍闭包概念前,我们先来看一段简短的代码 def sum_calc(*args): def wrapper(): sum = 0 for n in args: sum += n; r ...

  4. 跳表(SkipList)设计与实现(Java)

    微信搜一搜「bigsai」关注这个有趣的程序员 文章已收录在 我的Github bigsai-algorithm 欢迎star 前言 跳表是面试常问的一种数据结构,它在很多中间件和语言中得到应用,我们 ...

  5. Python文件部分(不包括数据)

    一,基本操作过程:1.a = open(文件名 ,打开方式) 2.a.read(size) | a.readline(size) | a.readlines(hint) 或 a.write(s) | ...

  6. 微服务痛点-基于Dubbo + Seata的分布式事务(TCC模式)

    前言 Seata 是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务.Seata 将为用户提供了 AT.TCC.SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案. ...

  7. java.lang.NoSuchMethodError的解决办法

    开发一个知识图谱在线服务(基于springcloud+vue)构建中医理论的知识图谱构建帕金森的知识图谱提供免费的知识图谱服务,希望能为朋友们的生活.学习.工作提供帮助(敬请期待)PS:关注后,点击头 ...

  8. 发送微信通知 java

    //实现类@Service public class WeChatServiceImpl implements IWeChatService { @Override public WeChatSend ...

  9. Nginx压力测试问题

    [root@aa~]# This is ApacheBench, Version 2.3 <Revision:655654Revision:655654> Copyright 1996 A ...

  10. 【函数分享】每日PHP函数分享(2021-1-9)

    implode() 将一个一维数组的值转化为字符串. string implode ( string $glue , array $pieces ) 参数描述 glue     默认为空的字符串. p ...