zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    阅读prettytable 一些代码、get、set 检查参数
    python 库 PrettyTabble 使用与错误
    python 内建模块与第三方模块
    python 排序 堆排序
    python 排序 桶排序
    python 排序冒泡排序与双向冒泡排序
    python 函数式编程 闭包,返回一个函数
    python 排序 选择排序
    python 排序 归并排序
    python 排序 插入排序与希尔排序
  • 原文地址:https://www.cnblogs.com/itech/p/3157654.html
Copyright © 2011-2022 走看看