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;
posted @   iTech  阅读(885)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
历史上的今天:
2010-06-26 商业软件、共享软件和自由软件
点击右上角即可分享
微信分享提示