0

我很难找到这个问题的解决方案。在 PHP 中为这个问题提出任何解决方案。

我有一个名为 test_repeat 的表

id  start   repeater   length     final
 1   20       2           3         50
 2   10       50          4        500

我的查询是

SELECT T.id AS ID, T.start AS start, T.repeater AS repeater 
       T.length AS length, T.final AS final
FROM `test_repeater` T
RIGHT JOIN `test_repeater` T2 ON T.id = T2.id 
WHERE T.start>=10 and T2.start*T2.repeater<=300

我得到的结果是

ID  start  repeater   length    final    
1   20       2          3        50       
2   10       5          12       500    

我想要得到的是这样的结果,即每个起始值都与转发器一起添加,并使该值成为下一个原始值,直到最终条件适用(请参见下文)

我梦想的结果会是这样

   ID   start   repeater   length     final
   1     20       2           3         50
   1     22       2           3         50
   1     24       2           3         50
   1     ...      .           .         ...
   1     ...      .           .         ...
   1     50       2           3         50
   2     10       5           4         500
   2     15       5           4         500
   2     20       5           4         500
   2     25       5           4         500
   2     30       5           4         500
   2     35       5           4         500
   2     ...      .           .         ...
   2     ...      .           .         ...
   2     ...      .           .         ...
   2     500      5           4         500
4

2 回答 2

1

好的。这更有意义...

 DROP TABLE IF EXISTS test_repeat;

 CREATE TABLE test_repeat
 (id  INT NOT NULL AUTO_INCREMENT PRIMARY KEY
 ,start   INT NOT NULL
 ,repeater   INT NOT NULL
 ,length     INT NOT NULL
 ,final INT NOT NULL
 );

 INSERT INTO test_repeat VALUE
 (1,   20       ,2           ,3         ,50),
 ( 2   ,10       ,5          ,4        ,500);


 DROP TABLE IF EXISTS ints;

 CREATE TABLE ints(i INT NOT NULL PRIMARY KEY);

 INSERT INTO ints VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);



 SELECT r.id
      , r.start+(r.repeater*(i2.i*10+i1.i)) start
      , repeater
      , length
      , final 
   FROM test_repeat r 
   JOIN ints i1
   JOIN ints i2
  WHERE r.start+(r.repeater*(i2.i*10+i1.i)) BETWEEN r.start AND r.final
  ORDER 
     BY id
      , start;
于 2013-02-01T13:53:22.800 回答
0
    SELECT T.id AS ID, T.start*T.repeater AS mymultipliedstart, 
           T.length AS length, T.final AS final
    FROM `test_repeater` T
    RIGHT JOIN `test_repeater` T2 ON T.id = T2.id 

WHERE T.start>=10 and T2.start*T2.repeater<=300
于 2013-02-01T13:30:02.643 回答