• 常用sql


    -- left join 以左表为主表 匹配右表中的数据
    select * from table1 ll
    left join(
    select * from table1_his ) his
    on ll.sbbh = his.sbbh


    -- union all 合并结果集 union 取出两个表中不重复的列
    select * from(
    select his.sbbh from table1_his his
    union
    select ll.sbbh from table1 ll ) where rownum <= 4

    -- rownum 伪列 ps:有子查询时需要给rownum 取别名 避免数据库不知道是哪个表的rownum 造成报错 rownum不支持大于号 只支持小于号
    select ll.sbbh from table1 ll where rownum <= 10

    -- rownum + order by
    select * from table1 ll where rownum <= 10 order by ll.inserttime

    -- rownum 实现分页 pageNumber 页数 pageSize 每页显示条数
    select * from (select rownum rm, a.* from (select * from table1) a where rownum <= pageNumber * pageSize ) b where b.rm > (pageNumber -1 ) * pageSize

    -- group by 分组
    select ll.wzbh,ll.sbbh from table1 ll group by wzbh,sbbh

    GROUP BY

    (1)oracle 中,总所周知,select (查询字段) from table1 group by column1 ,column2,,,,,,

    其中查询字段只能是column1,column2,,,,,,和其他列的聚合函数,其中红色字体要完全一致,

    (2)但是在mysql中,当查询字段未出现在group by 后面的字段,竟然也可以执行

    PS:下划线内容 粘贴自:https://www.cnblogs.com/iliuyuet/p/5404877.html

    往事如烟,余生有我.
  • 相关阅读:
    R()函数的使用 tp2
    __call()的使用
    tp3.1.3 引入静态页面
    tp3.1.3创建应用
    .env文件的使用 thinkphp51
    concat()和push()的区别
    小程序模板template使用
    56. 从1到n整数中1出现的次数
    55. 连续子数组的最大和
    54. 数据流中的中位数
  • 原文地址:https://www.cnblogs.com/assistants/p/10348732.html
Copyright © 2020-2023  润新知