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

posted @ 2019-02-02 16:48  闻长歌而知雅意  阅读(116)  评论(0编辑  收藏  举报