mysql vlookup楼层

时间:2012-06-03 03:22:28

标签: mysql

我有一个带有以下id值的navicat表:

VALUES: (5),(7),(9),(10),(25),(50),(55),(56),(62),(63),(64),(65),(68),(70),(72),(80);

我有查询:

select 
a.id as first_id_number, 
b.id as second_id_number, 
((b.id - a.id) * 2) + b.id as third_id_number
from my_table as a
join my_table as b 
on a.id = (select max(id) from my_table where id < b.id)
where ((b.id - a.id) * 2) + b.id in (select id from my_table);

但是,查询仅在连续行之间应用公式。 我想查询所有可能的组合,其中: ((更高的ID号 - 更低的ID号)* 2)+更高的ID号等于第三个ID号。

例如:

更高的id号码更低的id号码第三个id号码 5 25 65 50 55 65 62 63 65

在mysql中可以吗?

由于

1 个答案:

答案 0 :(得分:0)

您是否考虑使用三个而不是两个my_table别名,生成完整的交叉产品并将您的条件移至where子句?即。

select
a.id as first_id_number,
b.id as second_id_number,
c.id as third_id_number
from my_table as a, my_table as b, my_table as c
where <your fomula>