zoukankan      html  css  js  c++  java
  • PLSQL温习

    1.SELECT PRODUCT_NAME, PRODUCT_PRICE*0.8 FROM PRODUCT

    此处可以直接用乘法,取出的是打折后的价格

    ---------------------------------------------------------------------------------------------------------------

    2.select user_name,to_char(sysdate,'YYYY')-to_char(user_birthday,'YYYY') as user_age from user

    此处可以用to_char函数计算出日期的年部分,然后相减得出用户的年龄

    ---------------------------------------------------------------------------------------------------------------

    3.select user_birthday from user where between '1-1-83' and '1-1-84'

    检索生日大于83年1月1日,且小于84年1月1日的;与之相反,not between ... and ...则是大于等于下限值,小于等于上限值

    ---------------------------------------------------------------------------------------------------------------

    4.通配符

    _:一个下划线表示任意单个字符

    %:表示任意多个字符(含0个字符)

    [abc]或[a-c]:属于字符集合中的任意一个字符

    [^abc]或[^a-c]:不属于字符几何中的任意一个字符

    ---------------------------------------------------------------------------------------------------------------

    5.空值判断

    is null不能用 = null  来代替;null也不等于''

    ---------------------------------------------------------------------------------------------------------------

    6.rownum

    select * from user where rownum <= 10

    查询前10条;rownum是从1开始的!

    ---------------------------------------------------------------------------------------------------------------

    7.group by

    select categroy_id , count(product_id) from product group by category_id

    一般group by 都会跟着统计函数在一起  如:count(...)

    ---------------------------------------------------------------------------------------------------------------

    8.having

    select categroy_id , count(product_id) from product group by category_id having count(product_id)>10

    对分组的数据进行过滤,不能使用where子句,因为where子句在分组之前执行过滤,having子句在分组之后执行过滤

    ---------------------------------------------------------------------------------------------------------------

    9.exists

    select product_id from product where exists ( select * from important_product )

    exists返回的是一个逻辑值;与之相反是not exists

    ---------------------------------------------------------------------------------------------------------------

    10.All与any

    select  price from product where price < all ( select price from important_product)

    < all小于子查询结果集中的最小值

    > all大于子查询结果集中的最大值

    > any 大于子查询结果集中的最小值

    < any 小于子查询结果集中的最大值

    ---------------------------------------------------------------------------------------------------------------

    其他容易记住的就不一一列出了

  • 相关阅读:
    全面了解Nginx主要应用场景
    手把手教你构建 C 语言编译器
    Docker镜像原理和最佳实践
    Docker网络深度解读
    PostgreSQL 10.0 preview 功能增强
    阿里沈询:分布式事务原理与实践
    CPU、内存、IO虚拟化关键技术及其优化探索
    原理、方法双管齐下,大神带你细解Redis内存管理和优化---场景研读
    ASP.NET 5已终结,迎来ASP.NET Core 1.0和.NET Core 1.0 转
    RabbitMQ学习系列
  • 原文地址:https://www.cnblogs.com/liulun/p/2084072.html
Copyright © 2011-2022 走看看