常用SQL(一)
--查看全表
select * from emp;
--IN 和 NOT IN
select * from emp where sal in (800,1600);
--等价于
select * from emp where sal=800 or sal=1600;
-- BETWEEN…AND… 范围(在上限和下限之间)
select * from emp where sal between 800 and 1600;
--等价于
select * from emp where sal>=800 and sal<=1600;
-- IS NULL 和 IS NOT NULL 找出NULL值或非NULL 值
-- 遇到null,则一定要用is
select * from emp where comm = null;
--LIKE 模式匹配(或模糊查询) 在搜索字符串中使用通配符 “%”和”_” ,“%”号代表0个或多个字符,
--而”_”则表示单个字符.如果搜索字符串中需要查询实际的”%”和”_”,那么就需要在搜索字符串中使
--用一个转义字符(ESCAPE character),如果查一个叫以”刘%” 开头的名字
select name from table where name like ‘刘%%’ escape ‘\’;