oracle sql 高级
1 时间
如果是从当前时间到前一个月的这个时候之间的记录总条数:
select
count
(1)
from
uis_md_stcustom u
where
firsttime
between
add_months(sysdate,-1)
and
sysdate;
如果是求当前时间的前面一个月的内的记录总条数:
select
count
(1)
from
uis_md_stcustom u
where
to_char(firsttime,
'mm'
) = to_char(add_months(sysdate,-1),
'mm'
);
2 IN/ANY
IN- Equal toany member in the list
ANY- Compare value to**each** value returned by the subquery
ALL- Compare value to**EVERY** value returned by the subquery
<ANY()- less than maximum
>ANY()- more than minimum
=ANY()- equivalent toIN>ALL()- more than the maximum
<ALL()- less than the minimum
eg:
Find the employees who earn the same salary as the minimum salary for each department-
SELECT last_name, salary,department_id
FROM employees
WHERE salary IN(SELECT MIN(salary)FROM employees
GROUPBY department_id);
Employees who are not IT Programmers and whose salary is less than that of any IT programmer-
SELECT employee_id, last_name, salary, job_id
FROM employees
WHERE salary <ANY(SELECT salary
FROM employees
WHERE job_id ='IT_PROG')AND job_id <>'IT_PROG';
Employees whose salary is less than the salary ofall employees with a job ID of IT_PROG and whose job is not IT_PROG-
SELECT employee_id,last_name, salary,job_id
FROM employees
WHERE salary <ALL(SELECT salary
FROM employees
WHERE job_id ='IT_PROG')AND job_id <>'IT_PROG;