【发布时间】:2014-11-12 08:52:51
【问题描述】:
我有一张收入表,其中有 4436 条记录,有两列 - no_id(这是唯一的)和 payments。
我想提取一个查询,它会给出一行间隔为 100 的开始和结束列。一百的间隔可以根据用户输入而变化,可以是 1-250 之间的任何值。
原表
no_id, payments
4436, 7540
4435, 7900
4434, 8000
4433, 4500
'
'
'
'
1,2000
我期待这样的输出-
start, end
4436,4337
4336,4237
4236,4137
4136,4037
我写了一个连接语句。我正在检查我的错误以及我需要更正的地方。
SELECT (table2.no_id*100)-100+1 as start, table1.no_id as end,
table1.payments FROM earnings as table1, earnings as table2
WHERE (table1.no_id= table2.no_id*100 AND table2.no_id>MOD(t2.max_no,100))
JOIN
(SELECT max(t2.no_id) as max_no FROM earnings as t2)
【问题讨论】: