标签:练习 code tor data- 关键字 efault 入职 ase theme
select name,sal
case
when sal <= 2000 THEN ‘过低‘
when sal >= 4000 THEN ‘过高‘
ELSE ‘OK‘
END AS stats FROM emp WHERE deptno = 10;
SELECT 档次,count(*) AS 人数
FROM(SELECT (CASE
WHEN sal<=1000 THEN ‘0000-1000‘
WHEN sal<=2000 THEN ‘1000-2000‘
WHEN sal<=3000 THEN ‘2000-3000‘
ELSE ‘好高‘ END) AS 档次,ename,sal FROM emp)
GROUP BY 档次
ORDER BY 1 ;
SELECT * FROM(SELECT rownum AS sn,emp.* FROM emp WHERE rownum <=2) WHERE sn=2;
//rownum是一次对数据进行标识,必须先有第一名再有第二名
SELECT * FROM emp WHERE rownum<=2;
SELECT empno,aname
FROM(SELECT empno,ename FROM emp ORDER BY dbms_random.value())
WHERE rownum <= 3;
SELECT * FROM v WHERE vname LIKE ‘%CED%‘;
错误:SELECT * FROM v WHERE vname LIKE ‘_BCE%‘;
正确:SELECT * FROM v WHERE vname LIKE ‘\_BCE%‘ ESCAPE ‘\‘;
因为在LIKE语句中%和_都是通配符,我的理解就是个数不同而已
错误:SELECT * FROM v WHERE vname LIKE ‘_\BCE%‘ ESCAPE ‘\‘ ;
正确:SELECT * FROM v WHERE vname LIKE ‘_\\BCE%‘ ESCAPE ‘\‘ ;
结果:_\BCDF
解释:双写转义字符,百分号和下划线的处理方式一样
SELECT EMPNO,ENAME,HIREDATE FROM emp WHERE deptno=10 ORDER BY 3 ASC;
SELECT empno,deptno,sal,ename,job FROM emp ORDER BY 2 ASC, 3 DESC;
SELECT TRANSLATE(‘ab 你好 bcadefg‘ , ‘abcdefg‘ , ‘1234567‘) AS NEW_STR FROM DUAL;
SELECT data,translate(data,‘-0123456789‘,‘-‘) AS ename FROM v ORDER BY 2 ;
思路:先将列中字母,也就是取出排序的依据另成一列ename,然后在排序,把数字和字母都替换为空;
select 信息
feom 表
where 时间列= last_day(时间列)-1
select 信息
from 表
where lower(last_name)=‘chen‘
select m.*
from employess e,employess m
where e.manager_id = m.manasger_id and e.last_name = ‘chen‘
select *
from employess
where employess_id = (
select manager_id
from employess
where last_name = "chen")
select employess_id , avg(salary)
from employess
group by employess_id
HAVING avg(SALARY)>8000
from employess
where employess_id = (
select employess_id
from employess
group by employess_id
having salary = min(avg(salary))
)
标签:练习 code tor data- 关键字 efault 入职 ase theme
原文地址:http://www.cnblogs.com/nzhbk/p/7749687.html