其他分享
首页 > 其他分享> > DQL_条件查询和约束_概述

DQL_条件查询和约束_概述

作者:互联网

条件查询:

  where字句后面跟条件

  用算符

   >  <   >=   <=   =   <>

   BETWEEN...AND

   IN(集合)

   Like

   IS Null

   and 或  &&

   or   或  ||  

   not  或  !

 

mysql

  

-- 查询年龄大于20岁
SELECT * FROM student WHERE age >    20;
-- 查询年龄大于等于20岁
SELECT * FROM student WHERE age >=    20;
-- 查询年龄等于20岁
SELECT * FROM student WHERE age =    20;
-- -- 查询年龄不等于20岁
SELECT * FROM student WHERE age !=    20;
SELECT * FROM student WHERE age <>    20;                                                                                                                
-- 查询年龄大于等于20岁 小于等于30
SELECT * FROM student WHERE age >=     20 && age <=30;    
SELECT * FROM student WHERE age >=     20 AND age <=30;
SELECT * FROM student WHERE age BETWEEN 20 AND 30;

-- 查询年龄22岁,19岁,25岁的信息
SELECT * FROM student WHERE age = 22 OR age = 19 OR age = 25;
SELECT * FROM student WHERE age IN (22,18,25);
-- 查询英语成绩不为null
SELECT * FROM student WHERE english = null; -- 不对的。null值不能使用=(!=)判断
SELECT * FROM student WHERE english IS null;

-- 查询英语成绩不为null
SELECT * FROM student WHERE english IS not NULL;

 

 

 

 

 

 

 

 

约束_概述

  概述:对表中的数据进行限定,保证数据的正确性有效和完整性

  分类:

    主键约束:primary key

    非空约束:not null

    唯一约束:unique

    外键约束:foreigen key

搜索

复制

标签:20,--,age,查询,概述,student,DQL,WHERE,SELECT
来源: https://www.cnblogs.com/12-12-12/p/16514063.html