欢迎来到银盒子的世界~
mysql
偏移函数 lag(expr,n,default)over(partition .. order by ..)
lead()用法类似,只是lag向上,lead向下
聚合函数可以使用开窗函数 类似于count (*) over(partition by .. order by ..) 但是有了order by partition by 就不起作用了,而且在union all时候不知为什么与group by的结果有出入,暂时没发现原因,猜测是因为partition by是先select再分类,group by 是先分类再计数,union all 后再partition by 所以结果不一样
case when 的语法
select id, (case when p_id is null then 'Root' when id in (select p_id from tree) then 'Inner' else 'Leaf' end) type from tree;