2

我想要做的是按相似性/相似性排序问题,然后根据Result表格中的点从 Point表格中获取结果。

示例:查询 = '德国位置'

我有以下表格:

表问题

+---------+-----------+---------------+---------------------------------+
| ques_id  | question                                                   |
+---------+-----------+---------------+---------------------------------+
|     1    |  Where is Germany located                                  |
+---------+-----------+---------------+---------------------------------+
|     2    |  where is Germany located on a map                         |
+---------+-----------+---------------+---------------------------------+
|     3    |  where is Germany located in Europe                        |
+---------+-----------+---------------+---------------------------------+

表格结果

+---------+-----------+---------------+---------------------------------+
| resu_id  | result                                                     |
+---------+-----------+---------------+---------------------------------+
|     1    |  Germany is located in Europe                              |
+---------+-----------+---------------+---------------------------------+
|     2    |  Northern hemisphere in Europe                             |
+---------+-----------+---------------+---------------------------------+
|     3    |  between France & Poland                                   |
+---------+-----------+---------------+---------------------------------+
|     4    |  Germany is located in central Europe                      |
+---------+-----------+---------------+---------------------------------+
|     5    |  South of Denmark                                          |
+---------+-----------+---------------+---------------------------------+
|     6    |  52 degrees North, 13 degrees East                         |
+---------+-----------+---------------+---------------------------------+
|     7    |  located on the continent of Europe                        |
+---------+-----------+---------------+---------------------------------+

表点

+---------+-----------+-----------+-----------+
| pont_id |  ques_id  |  resu_id  |  point    |
+---------+-----------+-----------+-----------+
|    1    |     2     |     6     |    10     |
+---------+-----------+-----------+-----------+
|    2    |     1     |     1     |    8      |
+---------+-----------+-----------+-----------+
|    3    |     2     |     7     |    7      |
+---------+-----------+-----------+-----------+
|    4    |     3     |     5     |    9      |
+---------+-----------+-----------+-----------+
|    5    |     3     |     4     |    8      |
+---------+-----------+-----------+-----------+
|    6    |     1     |     7     |    10     |
+---------+-----------+-----------+-----------+
|    7    |     3     |     2     |    6      |
+---------+-----------+-----------+-----------+
|    8    |     2     |     3     |    4      |
+---------+-----------+-----------+-----------+

我尝试过了

SELECT resu_id FROM `Point` WHERE ques_id is (**?**) ORDER BY `point`

期待结果

+---------+-----------+-----------+--------------------------------------------+
| ques_id |  resu_id  |  point    |    result                                  |
+---------+-----------+-----------+--------------------------------------------+
|    1    |     7     |     10    |    located on the continent of Europe      |
+---------+-----------+-----------+--------------------------------------------+
|    1    |     1     |     8     |    Germany is located in Europe            |
+---------+-----------+-----------+--------------------------------------------+
|    2    |     6     |     10    |    52 degrees North, 13 degrees East       |
+---------+-----------+-----------+--------------------------------------------+
|    2    |     7     |     7     |    located on the continent of Europe      |
+---------+-----------+-----------+--------------------------------------------+
|    2    |     3     |     4     |    between France & Poland                 |
+---------+-----------+-----------+--------------------------------------------+
|    3    |     5     |     9     |    South of Denmark                        |
+---------+-----------+-----------+--------------------------------------------+
|    3    |     4     |     8     |    Germany is located in central Europe    |
+---------+-----------+-----------+--------------------------------------------+
|    3    |     2     |     6     |    Northern hemisphere in Europe           |
+---------+-----------+-----------+--------------------------------------------+

按相关性对问题进行排序,然后根据分值对相应的结果进行排序。

谢谢大家的帮助,不要对我苛刻:)

4

2 回答 2

1

如果您正在寻找相关的结果数据,您可以尝试以下查询:

select 
   p.ques_id, p.resu_id, p.point,
--   q.question,
   r.result -- , p.pont_id
from
   result r
   inner join point p on ( r.resu_id=p.resu_id )
--   inner join question q on ( q.ques_id=p.ques_id and q.ques_id=? ) -- // use this if required
   inner join question q on ( q.ques_id=p.ques_id )
order by 
   q.ques_id, p.point desc, r.result desc
;

上述查询执行的输出:

+---------+---------+-------+--------------------------------------+
| ques_id | resu_id | point | result                               |
+---------+---------+-------+--------------------------------------+
|       1 |       7 |    10 | located on the continent of Europe   |
|       1 |       1 |     8 | Germany is located in Europe         |
|       2 |       6 |    10 | 52 degrees North, 13 degrees East    |
|       2 |       7 |     7 | located on the continent of Europe   |
|       2 |       3 |     4 | between France & Poland              |
|       3 |       5 |     9 | South of Denmark                     |
|       3 |       4 |     8 | Germany is located in central Europe |
|       3 |       2 |     6 | Northern hemisphere in Europe        |
+---------+---------+-------+--------------------------------------+
8 rows in set (0.00 sec)

删除select您不想再次选择的字段。

于 2012-06-03T10:56:49.790 回答
0

我相信你想要这个::

  SELECT result 
  FROM Result 
  inner join Point on (Result.resul_id=Point.resul_id)
  WHERE Point.ques_id = ? ORDER BY Point.point desc limit 1
于 2012-06-02T13:39:13.123 回答