where語句的查詢
--where子句 --查詢部門編號是10的所有的員工 select * from emp where deptno = 10; --查詢部門中工資是3000的員工 select * from emp where sal = 3000; --找到部門中編號是 7788的員工 select * from emp where empno = 7788; --查詢姓名為SCOTT的員工所有信息 --在使用where 查詢條件,字符串是單引號而且區分大小寫 select * from emp WHERE ename = 'SCOTT'; --查詢所有在日期是1981年5月1日入職的員工信息 --select * from emp where hiredate = '1981-5-1'; --日期默認格式是 DD-MON-YYYY 查詢條件按照日期來,日期也要加單引號 select * from emp where hiredate = '1/5月/1981'; --查詢工資大於3000的員工 select * from emp where sal>=3000; ---注意:sal=>3000 是錯誤的!數據庫將不認識此符號! --查詢工資范圍在1500-3000的員工所有信息 select * from emp where sal>=1500 and sal<=3000; -- between..and...表示介於 兩個值之間,包涵邊界值 select * from emp where sal between 1500 and 3000; --查詢姓名是KING和SCOTT的詳細信息 select * from emp where ename = 'KING' or ename ='SCOTT'; --IN 表示出現在集合中的記錄 select * from emp where ename in ('KING','SCOTT'); --查詢工資不等於3000的員工信息 select * from emp where sal <> 3000; --method1 select * from emp where sal !=3000; --method2 select * from emp where not sal = 3000; --method3 取反運算 --查詢所有沒有提成的員工的信息 -- is null 表示某個字段為空 不為空 is not null select * from emp where comm is not null; -- 取反的意思 where not comm is null select * from emp where not comm is null; -- not 也可以代表取反的意思 select * from emp where ename not in ('KING','SCOTT'); --查詢所有姓名以s開頭的員工信息 -- 使用 like 和 通配符 -- 兩個通配符 %代表0個或者多個字符 _一個字符 select * from emp where ename like '%S'; ---字符(或是' ')里面嚴格區分大小寫。建議全部大寫書寫語句! --查詢名字中帶有0的 select * from emp where ename like '%O%'; --查詢第二個字母是L的員工的所有信息 select * from emp where ename like '_L%'; --查詢員工姓名中帶有_的所有的信息 --ESCAPE ‘’ 相當於自己定義一個轉義符 select * from emp where ename like '%a_%' ESCAPE 'a';