1

我有两个表,其描述如下:

record(record_id,min_index,max_index)

points(point_id,point_name,val1,val2,rank), point_id being on auto-increment

, from记录表指向点表中的 point_ids min_index。即对于特定记录,相应的点是>=min_index 和<=max_index。max_index

我需要合并这两个表,最终表类似于这样

points(point_id,record_id,point_name,val1,val2,rank)

我知道这违反了规范化标准,但这似乎对我遇到的问题非常有效。我不确定如何合并这两个表。

4

2 回答 2

2

只需使用 MySQL 的运算符连接BETWEEN ... AND ...表来指定您的连接条件:

SELECT points.point_id,
       record.record_id,
       points.point_name,
       points.val1,
       points.val2,
       points.rank
FROM   points JOIN record ON
         points.point_id BETWEEN record.min_index AND record.max_index
于 2012-09-17T10:14:50.837 回答
0
SELECT a.point_id,
   b.record_id,
   a.point_name,
   a.val1,
   a.val2,
   a.rank
from points a , record b
where ((point_id>=min_index)and (point_id<=max_index))
于 2012-09-17T10:21:18.630 回答