select*from 表名 where 列名 like'%value%';select*from 表名 where 列名 like'value%';select*from 表名 where 列名 like'value_%';
4. 连接(||)
|| 可以将两个字符串连接起来
SELECT 列1|| 列2 别名 FROM 表;
5. 逻辑运算
1.and:只有当两个表达式的值都为真的时候才会返回真
select
name,
years *12- leaves a1
from 表
where name
like'B%'and years *12- leaves >60;select*from
表
where years >=5and(years *12- leaves)/(years *12)<0.50;2.or:当其中一个条件为真时,其结果为真
select*from
表
where years >=5or(years *12- leaves)/(years *12)>=0.50;3.not:条件取反,
条件为假时结果为真,条件为真时结果为假,当not应用于null时可以使用is.select*from 表 where 列 notlike'B%';select*from 表 where 列 isnotnull;
6. 集合运算(SET)
union:将返回两个查询的结果并去除其中重复的部分。
select name from
表1unionselect name from 表2;unionall:对表进行合并,但是不去掉重复的记录。
select name from
表1unionallselect name from 表2;intersect(相交):返回两个表中共有的行(即两个表都存在的记录)。
select*from
表1intersectselect*from 表2;
minus(相减):返回的记录是存在于第一个表中但不存在于第二张表的记录。
select*from
表1
minus select*from 表2;(inandbetween)从属运算:
SELECT*FROM
表
WHERE STATE='CA'OR STATE ='CO'OR STATE ='LA';
另外一种写法:
SELECT*FROM 表
WHERE STATE IN('CA','CO','LA');
查找某一范围的记录:
select*from price
where 列1>0.50and 列1<0.75;
或者使用between:
select*from price
where 列1between0.25and0.75;