admin管理员组

文章数量:1794759

SQL基础

SQL基础

学习重点

  • 通过逻辑运算符,可以将多个查询条件进行组合。
  • 通过NOT运算符可以做成"不是~"这样的查询条件。
  • 两边条件成立时,使用 and 运算符的查询条件才成立。
  • 只要两边的条件中有一个成立,使用 or 条件才成立。
  • 值可以归结为真(TRUE)和假(FALSE)。比较运算符在比较成立时返回真,不成立时返回假。但是在SQL中还存在另一个特定的真值——不确定(UNKNOWN)。

NOT运算符 NOT不能单独使用,必须和其他查询条件组合起来使用。

select shohin_mei from shohin where not hanbai_tanka >=1000;

从表shohin 中选取列hanbai_tanka中不大于等于1000的对应shohin_mei数据。

and 运算符和or运算符 在where子句中使用and运算符或 or运算符,可以对多个查询条件进行组合。 and 的含义是“并且” or 的含义是“或者”

select shohin_mei,shiire_tamke from shohin where shohin_bunrui = '厨房用品' and hanbai_tanka >= 3000;

含义:从表shohin中查询 满足列shohin_bunrui为“厨房用品”,【并且】列 hanbai_tanka>=3000的信,输出对应的shohin_mei,shiire_tamke列信。 ############ 如果将 and 换成 or 含义:从表shohin中查询 满足列shohin_bunrui为“厨房用品”,【或者】列 hanbai_tanka>=3000的信,输出对应的shohin_mei,shiire_tamke列信 and 优先于 or where ‘aaa’ and ‘bbb’ or ‘ccc’ ==含义=> where (‘aaa’ and ‘bbb’) or ‘ccc’

使用()强化 or where ‘aaa’ and (‘bbb’ or ‘ccc’ ) ==含义=> 括号内优先执行

逻辑运算符和真值

练习题

本文标签: 基础SQL