常用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

上一篇:Oracle rownum和row_number()


下一篇:(2) 如何根据测试数据驱动文件来进行循环请求次数