差分及延3差分在MySQL数据库中实现
来源:互联网 发布:淘宝上的快排能买吗 编辑:程序博客网 时间:2024/04/30 05:01
前提:comm延续
sal_1:差分
sal_2:延3差分
select u1.empno,u1.sal,u1.comm,u1.sal_1,u2.sal_2
from
(select t.empno,t.sal,t.comm,sal-(select sal from test.emp t2 where t2.comm +1 = t.comm order by comm) as sal_1
from test.emp t
order by comm) u1 LEFT JOIN
(select t.comm+3 as comm,sal-(select sal from test.emp t2 where t2.comm +1 = t.comm order by comm) as sal_2
from test.emp t
order by comm) u2
ON u1.comm = u2.comm;
在MySQL4.1中子查询是不能使用LIMIT的,手册中也明确指明 This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’
也就是说,这样的语句是不能正确执行的。
select * from table where id in (select id from table limit 10);
但是,只要你再来一层就行。。如:
select * from table where id in (select t.id from (select * from table limit 10)as t)
select u1.empno,u1.sal,u1.comm,u1.sal_1,u2.sal_2
from
(select t.empno,t.sal,t.comm,sal-(select sal from test.emp t2 where t2.comm +1 = t.comm order by comm) as sal_1
from test.emp t
order by comm) u1 LEFT JOIN
(select t.comm+3 as comm,sal-(select sal from test.emp t2 where t2.comm +1 = t.comm order by comm) as sal_2
from test.emp t
order by comm) u2
ON u1.comm = u2.comm where
u1.empno not in (
select * from
(
select u.empno
from (
select u1.empno,u1.sal,u1.comm,u1.sal_1,u2.sal_2
from
(select t.empno,t.sal,t.comm,sal-(select sal from test.emp t2 where t2.comm +1 = t.comm order by comm) as sal_1
from test.emp t
order by comm) u1 LEFT JOIN
(select t.comm+3 as comm,sal-(select sal from test.emp t2 where t2.comm +1 = t.comm order by comm) as sal_2
from test.emp t
order by comm) u2
ON u1.comm = u2.comm) u limit 4) as t
)
empno, sal, comm, sal_1, sal_2
999, 808, 80, ,
998, 885, 81, 77,
997, 807, 82, -78,
996, 804, 83, -3,
995, 855, 84, 51, 77
994, 888, 85, 33, -78
993, 856, 86, -32, -3
- 差分及延3差分在MySQL数据库中实现
- 差分
- 差分
- 差分
- 差分阻抗-什么是差分?
- 【图-差分约束】 差分约束
- 分糖果 差分约束
- 曼彻斯特及差分曼彻斯特编码
- 差分信号概念及优点
- 差分约束系统C++实现
- 拉普拉斯差分滤波器模板实现+MATLAB
- 差分约束系统C++实现
- 差分约束系统
- 什么是差分信号?
- 差分信号详解
- 差分信号放大
- 关于差分信号
- 差分电路
- Codeforce 298 A snow Footprint 思维问题
- push,你到底做了啥事情????
- 标准输出的缓存问题
- oracle 10g rman 备份与恢复 之二
- 毕业5年后的总结
- 差分及延3差分在MySQL数据库中实现
- 禅道项目管理软件介绍
- ajax---简单使用Demo
- andoid 打包短信发送到gmail邮箱
- 如何在macox下面配置集成ios和android游戏教程
- AAC 文件解析及解码流程
- 利用pcntl_exec突破disable_functions
- 从概率看苹果系列设备及其它触摸类产品安全问题
- 手动脱壳----PECompact 2.x -> Jeremy Collake